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.
// 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]
});
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..
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.
@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
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.
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.
Fixed in fork v8.8.1
Should be fixed in graphql-tools@next. Can anyone check it out?
Closed by #1307, folded into #1306
Most helpful comment
I think what might be causing the problem is this part of the Shopify admin graphQL schema:
Since the field
queryis of typeQueryRoot, namely the entry point type for queries..