How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • import { makeExecutableSchema } from '@graphql-tools/schema'
    import { addMocksToSchema } from '@graphql-tools/mock'
    import { stitchSchemas } from '@graphql-tools/stitch'
    import { delegateToSchema } from '@graphql-tools/delegate'
    import { FilterRootFields, RenameTypes } from '@graphql-tools/wrap'
    
    const postSchema = makeExecutableSchema({
      typeDefs: /* GraphQL */ `
        type Post {
          id: ID!
          text: String
          userId: ID!
        }
        type Query {
          postById(id: ID!): Post
          postsByUserId(userId: ID!): [Post]!
        }
      `
    })
    
    const postsSubschema = {
      schema: addMocksToSchema({ schema: postSchema }),
      transforms: [
        // remove the "postsByUserId" root field
        new FilterRootFields((op, field) => field !== 'postsByUserId'),
        // prefix all type names with "Post_"
        new RenameTypes(name => `Post_${name}`)
      ]
    }
    
    const userSchema = makeExecutableSchema({
      typeDefs: /* GraphQL */ `
        type User {
          id: ID!
          email: String
        }
    
        type Query {
          userById(id: ID!): User
        }
      `
    })
    
    const usersSubschema = {
      schema: addMocksToSchema({ schema: userSchema })
    }
    
    const stitchedSchema = stitchSchemas({
      subschemas: [postsSubschema, usersSubschema],
      typeDefs: /* GraphQL */ `
        extend type User {
          posts: [Post_Post!]!
        }
        extend type Post_Post {
          user: User!
        }
      `,
      resolvers: {
        User: {
          posts: {
            selectionSet: `{ id }`,
            resolve(user, args, context, info) {
              return delegateToSchema({
                schema: postsSubschema,
                operation: 'query',
                fieldName: 'postsByUserId',
                args: { userId: user.id },
                context,
                info
              })
            }
          }
        },
        Post_Post: {
          user: {
            selectionSet: `{ userId }`,
            resolve(post, args, context, info) {
              return delegateToSchema({
                schema: usersSubschema,
                operation: 'query',
                fieldName: 'userById',
                args: { id: post.userId },
                context,
                info
              })
            }
          }
        }
      }
    })
    
    Docs
  • import { makeExecutableSchema } from '@graphql-tools/schema'
    import { addMocksToSchema } from '@graphql-tools/mock'
    
    let postsSchema = makeExecutableSchema({
      typeDefs: /* GraphQL */ `
        type Post {
          id: ID!
          message: String!
          author: User!
        }
    
        type User {
          id: ID!
          posts: [Post]!
        }
    
        type Query {
          postById(id: ID!): Post
          postUserById(id: ID!): User
        }
      `
    })
    
    let usersSchema = makeExecutableSchema({
      typeDefs: /* GraphQL */ `
        type User {
          id: ID!
          email: String!
        }
    
        type Query {
          userById(id: ID!): User
        }
      `
    })
    
    // just mock the schemas for now to make them return dummy data
    postsSchema = addMocksToSchema({ schema: postsSchema })
    usersSchema = addMocksToSchema({ schema: usersSchema })
    Docs
  • import { makeExecutableSchema } from '@graphql-tools/schema'
    import { addMocksToSchema } from '@graphql-tools/mock'
    
    let postsSchema = makeExecutableSchema({
      typeDefs: /* GraphQL */ `
        type Post {
          id: ID!
          message: String!
          author: User!
        }
    
        type User {
          id: ID!
          posts: [Post]!
        }
    
        type Query {
          postById(id: ID!): Post
          postUserById(id: ID!): User
        }
      `
    })
    
    let usersSchema = makeExecutableSchema({
      typeDefs: /* GraphQL */ `
        type User {
          id: ID!
          email: String!
        }
    
        type Query {
          userById(id: ID!): User
        }
      `
    })
    
    // just mock the schemas for now to make them return dummy data
    postsSchema = addMocksToSchema({ schema: postsSchema })
    usersSchema = addMocksToSchema({ schema: usersSchema })
    
    Docs
  • var params = {
      RegistryName: 'STRING_VALUE', /* required */
      SchemaName: 'STRING_VALUE', /* required */
      ClientTokenId: 'STRING_VALUE',
      Content: 'STRING_VALUE',
      Description: 'STRING_VALUE',
      Type: OpenApi3 | JSONSchemaDraft4
    };
    schemas.updateSchema(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });
    Docs
  • var params = {
      RegistryName: 'STRING_VALUE', /* required */
      SchemaName: 'STRING_VALUE', /* required */
      SchemaVersion: 'STRING_VALUE'
    };
    schemas.describeSchema(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples