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

mergeSchemas not working with Shopify Admin GraphQL schema #892

Closed
dhmacs opened this issue Jul 17, 2018 · 8 comments
Closed

mergeSchemas not working with Shopify Admin GraphQL schema #892

dhmacs opened this issue Jul 17, 2018 · 8 comments
Labels
blocking Prevents production or dev due to perf, bug, build error, etc.. has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@dhmacs
Copy link

dhmacs commented Jul 17, 2018

I'm trying to extend the Shopify Admin GraphQL api with my own endpoints, but as soon as I call margeSchemas I get the following error:

Failure: Can't find type QueryRoot

For now, I'm just passing the shopify schema to the mergeSchemas function, yet it does not work.

Repro

// The introspection query is made at build time, therefore the schema is just imported
import schema from "./admin.graphql";

// ...

const { accessToken, shopName } = event.requestContext.authorizer;

const http = new HttpLink({
  uri: `https://${shopName}.myshopify.com/admin/api/graphql.json`,
  fetch 
});

const link = setContext((request, previousContext) => ({
  headers: {
    "Content-Type": "application/json",
    "X-Shopify-Access-Token": accessToken
  }
})).concat(http);

const executableSchema = makeRemoteExecutableSchema({ schema, link });

// Only the Shopify admin api schema is passed for now, additional schemas will be added
const mergedSchema = mergeSchemas({
    schemas: [executableSchema]
});
@ghost ghost added blocking Prevents production or dev due to perf, bug, build error, etc.. has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository labels Jul 17, 2018
@dhmacs
Copy link
Author

dhmacs commented Jul 17, 2018

I think what might be causing the problem is this part of the Shopify admin graphQL schema:

"""
A job corresponds to some long running task that the client should poll for status.
"""
type Job {
  """This indicates if the job is still queued or has been run."""
  done: Boolean!
  id: ID!

  """
  This field will only resolve once the job is done.Can be used to ask for object(s) that have been changed by the job.
  """
  query: QueryRoot
}

Since the field query is of type QueryRoot, namely the entry point type for queries..

@smcardle
Copy link

smcardle commented Jul 17, 2018

This is correct.

I have exactly the same issue and initially raised a point on the Shopify Forum, however, this is an issue with the graphql-tools library and not the Shopify Admin Schema.

I have managed to get over this temporarily by doing the following prior to calling makeRemoteExecutableSchema-:

...
const schema = await introspectSchema(link);

// Remove the query field from the Job type as this causes issues when merging the schemas
delete schema['_typeMap']['Job']['_fields'].query;
return makeRemoteExecutableSchema({
    schema,
    link,
    logger: { log: e => console.log(e) }
});

This only affects the Job type and as I currently have no need to inspect the current status of jobs this is not an issue for me.
Every thing else in the Shopify Admin GraphQL Schema is now mergable with all of my other schemas.

@dhmacs
Copy link
Author

dhmacs commented Jul 17, 2018

@smcardle Yes I've found the same work around, but I'm using a schema transformation:

transformSchema(executableSchema, [
    new FilterTypes(filter => {
      return filter.toString() !== "Job";
    })
])

I hope I won't need to query for jobs any time soon.. Hopefully this issue can be fixed by graphql-tools

@danielrearden
Copy link
Collaborator

FWIW here's a simple repro. Changing the root type names to the expected defaults (Query and Mutation) resolves the issue. I suspect it's because the names for those types are hardcoded in the source code.

@yaacovCR
Copy link
Collaborator

yaacovCR commented Mar 6, 2020

Fixable in graphql-tools-fork using new RenameRootTypes transform.

See example in: https://runkit.com/yaacovcr/mergeschemas-with-custom-root-query-name

Note that I changed the original reproduction to use separate DoSomethingPayload and DoSomethingElsePayload types in the two schemas. If you add the { ..., mergeTypes: true } option to mergeSchemas, this is not necessary.

@yaacovCR
Copy link
Collaborator

yaacovCR commented Mar 8, 2020

Fixed in fork v8.8.1

@yaacovCR
Copy link
Collaborator

Should be fixed in graphql-tools@next. Can anyone check it out?

@yaacovCR
Copy link
Collaborator

yaacovCR commented Apr 1, 2020

Closed by #1307, folded into #1306

@yaacovCR yaacovCR closed this as completed Apr 1, 2020
@yaacovCR yaacovCR mentioned this issue Apr 1, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking Prevents production or dev due to perf, bug, build error, etc.. has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

No branches or pull requests

4 participants