cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety
https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/
MIT License
204 stars 25 forks source link

gatsby-source-graphql & Apollo client #99

Closed carstenblt closed 2 years ago

carstenblt commented 4 years ago

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

Thank you for your help!

cometkim commented 4 years ago

To clarify,

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

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?

carstenblt commented 4 years ago

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",
      },
},
cometkim commented 4 years ago

I saw you just filed another issue https://github.com/dotansimha/graphql-code-generator/issues/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.

cometkim commented 2 years ago

This is fixed in v3 (current RC)

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