Update Documentation for GraphQL for Nodejs

We should be using the latest apollo/client but if you want to approach with Node.js either you import or require form @apollo/client/core

//Node.js Example 
// npm install @apollo/client graphql apollo-link-prismic --save
import { PrismicLink } from 'apollo-link-prismic';
import { ApolloClient, InMemoryCache, gql } from '@apollo/client/core';

import config from '~/config';

const client = new ApolloClient({
  link: PrismicLink({
    uri: config.PRISMIC_URI,
    accessToken: config.PRISMIC_ACCESS_TOKEN,
  }),
  cache: new InMemoryCache(),
});
....
const { data } = (await client.query({
          query: gql`
             query($lang: String!) {
                 blog(uid: "some_id", lang: $lang) {
                    ... 
                 }
             }
          `, 
         variables: {
            lang,
          },
        })
      ).data;

Hello Semir, welcome to the Prismic community!

Thanks for the insight. Is this recommendation based on an example project that you saw in the documentation, or an article, if it is, could you share it with me?

You're saying it'll be useful to use @apollo/client/core instead of appollo-client from npm, is that right ?

Hi Paulina and thank you

Yes I would suggest to use the @apollo/client as they have the latest patches and if you want to use it for Node.JS you would have to import it under core, ex: @apollo/client/core.

The reason I want to suggest this is because using the old appollo-client you would run into a common warning error known as heuristic fragment. There is a solution but I don't want to build an extra layer work around, and this is fixed within the @apollo/client.

I have experienced this, because when running query(...){...} on https://project.prismic.io/graphql works out perfectly, but when trying to run the query in the client of appollo-client the warning kicks off.

Anyhow I hope this helps out to anyone out there

Regards,
Semir

1 Like

That is very helpful, I'll add this information to the Education team backlog so we can have it in mind for future improvements in documentations and sample projects.

Could you point to me where you saw that we suggest/recommend this configuration? So that i have it in mind

Thanks again for the feedback

This issue has been closed due to inactivity. Flag to reopen.