Skip to content

Instantly share code, notes, and snippets.

@freiksenet
Last active April 6, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freiksenet/27ac99a19bba55fd3979b36e5f59c8ad to your computer and use it in GitHub Desktop.
Save freiksenet/27ac99a19bba55fd3979b36e5f59c8ad to your computer and use it in GitHub Desktop.
import { mergeSchemas, delegateToSchema } from 'graphql-tools';
const extensionSchema = `
interface Node {
id: ID!
}
extend type User implements Node {
id: ID!
}
extend type Blog implements Node {
id: ID!
}
extend type Query {
node(id: ID!): Node
}
`;
const schema = mergeSchemas({
schemas: [serviceSchema, extensionSchema],
resolvers: {
Query: {
node(parent, { id }, context, info) {
const { type, localId } = deserializeGlobalId(id);
let fieldName;
if (type === 'Blog') {
fieldName = 'blogById',
} else if (type === 'User') {
fieldName = 'userById',
} else {
throw new Error('Invalid global id');
}
return delegateToSchema({
schema: serviceSchema,
operation: 'query',
fieldName,
args: { id: localId },
context,
info,
});
},
},
// ... more resolvers
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment