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

gatsby-source-graphql & Apollo client #99

Closed
carstenblt opened this issue Aug 16, 2020 · 4 comments
Closed

gatsby-source-graphql & Apollo client #99

carstenblt opened this issue Aug 16, 2020 · 4 comments
Assignees
Labels
bug Something isn't working investigation upstream Issue by upstream
Milestone

Comments

@carstenblt
Copy link

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!

@cometkim cometkim added the question Further information is requested label Aug 18, 2020
@cometkim cometkim self-assigned this Aug 18, 2020
@cometkim
Copy link
Owner

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?

@carstenblt
Copy link
Author

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 cometkim added bug Something isn't working and removed question Further information is requested labels Aug 18, 2020
@cometkim
Copy link
Owner

cometkim commented Aug 18, 2020

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.

@cometkim cometkim added investigation upstream Issue by upstream labels Oct 23, 2020
@cometkim cometkim added this to the v3 milestone May 10, 2021
@cometkim cometkim mentioned this issue May 10, 2021
Closed
30 tasks
@cometkim
Copy link
Owner

This is fixed in v3 (current RC)

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

cometkim added a commit that referenced this issue Jun 12, 2022
rc.0
- implemente XState based scheduler
- stabilize schema output
- bump GCG
- upgrade yarn to v3
- rewritten core logics
- upgrade eslint to v8
- upgrade plugin's dependencies
- pin graphql version
- rewrite emitSchema service
- rewriten emitPluginDocument service
- rewriten codegen service
- add TS & Flow examples

rc.1
- skip running on cloud build
- fix config validation
- more contexture reporting
- turn `flattenGeneratedTypesIncludeFragments` true
- stabilize documents
- change maybe type to use `null` instead of `undefined`
- update README

rc.2
- add mdx example
- MDX example to validate regression of [#117]
- update dependencies
- added support for `GatsbyImageData` scalar

Resolves #40
Resolves #103
Resolves #104
Resolves #109
Fixes #113
Fixes #117
Fixes #120
Resolves #122
Fixes #124
Resolves #131
Fixes #139, #99
Resolves #146
Fixes #157
Fixes #159
Fixes #160
Fixes #161
Fixes #162
Resolves #168
Resolves #169
Fixes #171

[#117]: #117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation upstream Issue by upstream
Projects
None yet
Development

No branches or pull requests

2 participants