Advertisement
Guest User

CreateSchema

a guest
Nov 27th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. const {
  2. RenameTypes,
  3. transformSchema,
  4. introspectSchema,
  5. RenameRootFields,
  6. makeRemoteExecutableSchema
  7. } = require('graphql-tools')
  8. const fetch = require('node-fetch')
  9. const { HttpLink } = require('apollo-link-http')
  10.  
  11. module.exports = async function ({
  12. api, // gridsome api
  13. prefix, // new schema prefix
  14. uri // graphql source url
  15. }) {
  16.  
  17. api.createSchema( async (graphql) => {
  18.  
  19. const link = new HttpLink({
  20. uri,
  21. fetch,
  22. // headers: {}
  23. })
  24.  
  25. const schema = await introspectSchema(link)
  26.  
  27. const executableSchema = await makeRemoteExecutableSchema({ schema, link })
  28.  
  29. const transformedSchema = transformSchema(
  30. executableSchema, [
  31. new RenameTypes( (type) => `${prefix}${type}` ),
  32. new RenameRootFields( (operation, name) => `${prefix}${name}` )
  33. ]
  34. )
  35.  
  36. // schema to be created
  37. return transformedSchema
  38. })
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement