Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use plugin-graphql with SSR #92

Closed
mbajur opened this issue Apr 26, 2019 · 8 comments
Closed

Use plugin-graphql with SSR #92

mbajur opened this issue Apr 26, 2019 · 8 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mbajur
Copy link

mbajur commented Apr 26, 2019

Hello, I'm trying to use plugin-graphql with fresh nuxt.js app but details about that are not sufficient. I can see in FAQ that i need to use node-fetch and global.fetch = fetch but where exactly should i put that? In the store file definition? So far, my store/index.js looks as follows:

import VuexORM from '@vuex-orm/core'
import VuexORMGraphQL from '@vuex-orm/plugin-graphql'
import database from '~/db'
import fetch from 'node-fetch'

global.fetch = fetch

VuexORM.use(VuexORMGraphQL, { database })

export const plugins = [VuexORM.install(database)]

but app freezes (loading till infinity) when i'm trying to reach it in browser. Any tips much appreciated!

I'm using plugin-graphql ^1.0.0-rc.33

@mbajur mbajur changed the title Use that with SSR Use plugin-graphql with SSR Apr 26, 2019
@phortx
Copy link
Collaborator

phortx commented Apr 27, 2019

Hi!

My store/index.js:

import Vuex from 'vuex';
import VuexORM from '@vuex-orm/core';
import VuexORMGraphQL from '@vuex-orm/plugin-graphql';
import { HttpLink } from 'apollo-link-http';
import database from './database';
import fetch from 'node-fetch';

const options = {
  database,
  debug: process.env.NODE_ENV === 'development' && process.client,
  url: process.env.BACKEND_URL + '/api/v2',
};

if (process.server) {
  options.link = new HttpLink({ uri: options.url, fetch });
}

VuexORM.use(VuexORMGraphQL, options);


export default function createStore () {
  const plugins = [VuexORM.install(database)];
  return new Vuex.Store({ plugins });
}

Seems you're right, setting global.fetch is deprecated and probably doesn't work. I've simply setup a HttpLink instance and pass fetch. I will update the docs :)

Please let me know if this fixes your problem.

@phortx phortx added the bug Something isn't working label Apr 27, 2019
@phortx phortx self-assigned this Apr 27, 2019
@phortx phortx added this to the 1.0.0 milestone Apr 27, 2019
@mbajur
Copy link
Author

mbajur commented Apr 27, 2019

That was it! Thank you :)

@phortx
Copy link
Collaborator

phortx commented Apr 28, 2019

Nice, I'll update the docs :)

@phortx
Copy link
Collaborator

phortx commented Apr 29, 2019

Done.

@phortx phortx closed this as completed Apr 29, 2019
@renestalder
Copy link

Work like a charm. Don't you think it would be worth adding this as a separate page into the documentation (or at least to the setup page) instead of only the F.A.Q? SSR is quite a fundamental part of modern web applications and it took me quite some time finding this issue here for the concrete solution.

@phortx
Copy link
Collaborator

phortx commented May 3, 2019

That's exactly what I have done 😎

https://github.com/vuex-orm/plugin-graphql/blob/master/docs/guide/nuxt.md

It's just not deployed yet :)

@renestalder
Copy link

🆒 🆒 🆒 :)

@kieuminhcanh
Copy link

I can not use fetch, customQuery or customMutate on Nuxt. Any one same?
#134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants