Guest User

Untitled

a guest
Aug 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import { mergeSchemas } from 'graphql-tools';
  2.  
  3. const createNewSchema = async () => {
  4. // get remote executable schema
  5. const schema = await createRemoteExecutableSchema();
  6.  
  7. // write a resolver to customise the existing resolver
  8. const customResolvers = {
  9. Query: {
  10. game: (root, args, context, info) => {
  11. const validation = validateTime();
  12. // If validation fails, return empty, else delegate to parent schema
  13. if (!validation) {
  14. return [];
  15. } else {
  16. return info.mergeInfo.delegateToSchema({
  17. schema,
  18. operation: 'query',
  19. fieldName: 'game',
  20. args,
  21. context,
  22. info
  23. });
  24. }
  25. }
  26. }
  27. };
  28.  
  29. // merge the schema along with custom resolvers
  30. return mergeSchemas({
  31. schemas: [ schema ],
  32. resolvers: customResolvers
  33. });
  34. };
Add Comment
Please, Sign In to add comment