cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety

Home Page:https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gatsby-source-graphql & Apollo client

carstenblt opened this issue · comments

I am using gatsby-source-graphql to make remote data available under a given fieldName/namespace. I am accessing the same backend source with the Apollo client directly but without the fieldName that is defined for gatsby-source-graphql.

From my understanding this is breaking the plugin for me right now. I get Cannot query field ... on type "Query" for all Apollo calls. Is there either a way to

  • not parse the Apollo queries to get rid of the errors
  • adjust the namespace/tell the plugin to prefix the Apollo queries?

Thank you for your help!

To clarify,

you have one GraphQL backend, and you use it as both static and runtime queries at the same time. And you understand:

  • you can't mix those two types of queries.
  • gatsby-plugin-typegen only solves gatsby's problem, not Apollo.

In this case, as you say, the plugin shouldn't parse any queries provided by Apollo, so it's an obvious bug. Can you provide settings and snippets?

Right, even though at first I thought gatsby-plugin-typegen might be hackable to do both.

So my typical code looks like this:

import { graphql } from "gatsby";
import { gql } from "apollo-boost";

export const pageQuery = graphql`
  query {
    backend {
      someQuery
  }
  `
...
const otherQuery = await AClient.query({
      query: gql`{
          someOtherQuery
      }
      `
    });

with my gatsby-config.js plugins set up

{
      resolve: "gatsby-source-graphql",
      options: {
        typeName: "Backend",
        fieldName: "backend",
        url: "https://backend",
      },
},
```

I saw you just filed another issue dotansimha/graphql-code-generator#4586

if this problem is caused in graphql-codegen config without this plugin. then I can track this as an upstream issue and contribute to there. will let you know after looking at the details and finding any workaround.

This is fixed in v3 (current RC)

v3 relies on Gatsby's SET_GRAPHQL_DEFINITIONS API and doesn't use graphql-tag-pluck anymore.