Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {
- RenameTypes,
- transformSchema,
- introspectSchema,
- RenameRootFields,
- makeRemoteExecutableSchema
- } = require('graphql-tools')
- const fetch = require('node-fetch')
- const { HttpLink } = require('apollo-link-http')
- module.exports = async function ({
- addSchema, // gridsome api { addSchema }
- prefix, // new schema prefix
- uri // graphql source url
- }) {
- const link = new HttpLink({
- uri,
- fetch,
- // headers: {}
- })
- const schema = await introspectSchema(link)
- const executableSchema = await makeRemoteExecutableSchema({ schema, link })
- const transformedSchema = transformSchema(
- executableSchema, [
- new RenameTypes( (type) => `${prefix}${type}` ),
- new RenameRootFields( (operation, name) => `${prefix}${name}` )
- ]
- )
- // Stitch transformed schema
- addSchema(transformedSchema)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement