-
Notifications
You must be signed in to change notification settings - Fork 5
/
makeSchema.js
36 lines (33 loc) · 1.15 KB
/
makeSchema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const schema = require("./schema");
const { makeRemoteExecutableSchema, introspectSchema, mergeSchemas, delegateToSchema, FilterRootFields, transformSchema } = require('graphql-tools')
const { HttpLink } = require('apollo-link-http');
const fetch = require('node-fetch')
module.exports = async function makeSchema() {
const link = new HttpLink({ uri: 'https://api.graphcms.com/simple/v1/swapi', fetch})
const clientSchema = await introspectSchema(link);
const remoteSchema = makeRemoteExecutableSchema({ schema: clientSchema, link})
const transformedSchema = transformSchema(remoteSchema, [new FilterRootFields((operation, fieldName) => fieldName === 'allFilms')]);
return mergeSchemas({
schemas: [transformedSchema, schema, `
extend type Post {
movie: Film!
}
`],
resolvers: {
Post: {
movie(parent, args, context, info) {
return delegateToSchema({
schema: remoteSchema,
operation: 'query',
fieldName: 'Film',
args: {
title: "The Empire Strikes Back"
},
context,
info,
})
}
}
}
});
};