How to use the @kamilkisiela/graphql-tools.makeExecutableSchema function in @kamilkisiela/graphql-tools

To help you get started, we’ve selected a few @kamilkisiela/graphql-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ardatan / graphql-toolkit / tests / epoxy / merge-schemas.spec.ts View on Github external
serialize(value) {
                        return new Date(value).toISOString()
                    },
                    parseValue(value) {
                        return new Date(value);
                    },
                    parseLiteral(ast) {
                        if (ast.kind !== Kind.STRING) {
                            throw new TypeError(`Date cannot represent non string type`);
                        }
                        return new Date(ast.value);
                    }
                })
            }
        });
        const schemaB = makeExecutableSchema({
            typeDefs: [`type Query { b: String }`],
        });

        const schema = mergeSchemas({ schemas: [schemaA, schemaB] });

        // original schema A
        const { data: dataA } = await graphql({
            schema: schemaA,
            source: /* GraphQL */` { a } `
        });

        expect(dataA.a).toEqual(now.toISOString());

        // merged schema
        const { data } = await graphql({
            schema,
github ardatan / graphql-toolkit / tests / epoxy / merge-schemas.spec.ts View on Github external
it('should merge two valid executable schemas', async () => {
        const fooSchema = makeExecutableSchema({
            typeDefs: gql`
                type Query {
                    foo: String
                }
            `,
            resolvers: {
                Query: {
                    foo: () => 'FOO'
                }
            }
        });
        const barSchema = makeExecutableSchema({
            typeDefs: gql`
                type Query {
                    bar: String
                }
github ardatan / graphql-toolkit / tests / epoxy / merge-typedefs.spec.ts View on Github external
it('should accept root schema object', () => {
      const mergedSchema = mergeTypeDefs(['type RootQuery { f1: String }', 'type RootQuery { f2: String }', 'schema { query: RootQuery }', 'type MyType { field: Int } type RootQuery { f3: MyType }']);

      const schema = makeExecutableSchema({
        typeDefs: mergedSchema,
      });
      const queryType = schema.getQueryType();

      expect(queryType).toBeDefined();
      expect(queryType).not.toBeNull();
      expect(queryType.name).toEqual('RootQuery');
    });
github ardatan / graphql-toolkit / tests / epoxy / merge-typedefs.spec.ts View on Github external
it('should keep scalars', () => {
      const mergedSchema = mergeTypeDefs([buildSchema('scalar UniqueId')]);

      expect(print(mergedSchema).indexOf('scalar')).not.toEqual(-1);

      const schema = makeExecutableSchema({
        typeDefs: mergedSchema,
      });

      expect(schema.getType('UniqueId')).toBeDefined();
    });
github ardatan / graphql-toolkit / tests / utils / print-schema-with-directives.spec.ts View on Github external
it('Should print types correctly if they dont have astNode', () => {
    const schema = makeExecutableSchema({
      typeDefs: `
      scalar JSON
    
      type TestType {
        testField: JSON!
      }

      type Other {
        something: String
      }
    
      type Query {
        test: TestType
        other: Other!
      }
      `,
github ardatan / graphql-toolkit / tests / epoxy / merge-schemas.spec.ts View on Github external
it('should merge two valid executable schemas with extra typeDefs and resolvers', async () => {
        const fooSchema = makeExecutableSchema({
            typeDefs: gql`
                type Query {
                    foo: String
                }
            `,
            resolvers: {
                Query: {
                    foo: () => 'FOO'
                }
            }
        });
        const barSchema = makeExecutableSchema({
            typeDefs: gql`
                type Query {
                    bar: String
                }
            `,
            resolvers: {
                Query: {
                    bar: () => 'BAR'
                }
            }
        });
        const { errors, data } = await graphql({
            schema: mergeSchemas({
                schemas: [fooSchema, barSchema],
                typeDefs: gql`
                    type Query {
github ardatan / graphql-toolkit / tests / utils / resolvers-composition.spec.ts View on Github external
`
        const resolvers = {
            Query: {
                foo: async () => getFoo(),
            },
        };
        const resolversComposition: ResolversComposerMapping = {
            Query: {
                foo: next => async () => {
                    const prevResult = await next();
                    return getFoo() + prevResult;
                }
            }
        }
        const composedResolvers = composeResolvers(resolvers, resolversComposition);
        const schema = makeExecutableSchema({
            typeDefs,
            resolvers: composedResolvers,
        });
        
        const result = await execute({
            schema,
            document: gql`query { foo }`,
          });
          expect(result.errors).toBeFalsy();
          expect(result.data.foo).toBe('FOOFOO');
    });
    it('should be able to take nested composition objects for subscription resolvers', async () => {
github ardatan / graphql-toolkit / src / epoxy / merge-schemas.ts View on Github external
export function mergeSchemas({
    schemas,
    typeDefs,
    resolvers,
    resolversComposition,
    schemaDirectives,
    resolverValidationOptions,
    logger,
    exclusions,
}: MergeSchemasConfig) {
    return makeExecutableSchema({
        typeDefs: mergeTypeDefs([
            ...schemas,
            ...typeDefs ? asArray(typeDefs) : []
        ], { exclusions }),
        resolvers: composeResolvers(
            mergeResolvers([
                ...schemas.map(schema => extractResolversFromSchema(schema)),
                ...resolvers ? asArray(resolvers) : []
            ], { exclusions }),
            resolversComposition || {}
        ),
        schemaDirectives,
        resolverValidationOptions,
        logger
    })
}
github ardatan / graphql-toolkit / packages / schema-merging / src / merge-schemas.ts View on Github external
export async function mergeSchemasAsync({ schemas, typeDefs, resolvers, resolversComposition, schemaDirectives, resolverValidationOptions, logger, ...config }: MergeSchemasConfig) {
  const [typeDefsOutput, resolversOutput] = await Promise.all([
    mergeTypeDefs([...schemas, ...(typeDefs ? asArray(typeDefs) : [])], config),
    Promise.all(schemas.map(async schema => extractResolversFromSchema(schema))).then(extractedResolvers =>
      composeResolvers(mergeResolvers([...extractedResolvers, ...(resolvers ? asArray(resolvers) : [])], config), resolversComposition || {})
    ),
  ]);
  return makeExecutableSchema({
    typeDefs: typeDefsOutput,
    resolvers: resolversOutput,
    schemaDirectives,
    resolverValidationOptions,
    logger,
  });
}
github ardatan / graphql-toolkit / packages / schema-merging / src / merge-schemas.ts View on Github external
export function mergeSchemas({ schemas, typeDefs, resolvers, resolversComposition, schemaDirectives, resolverValidationOptions, logger, ...config }: MergeSchemasConfig) {
  return makeExecutableSchema({
    typeDefs: mergeTypeDefs([...schemas, ...(typeDefs ? asArray(typeDefs) : [])], config),
    resolvers: composeResolvers(mergeResolvers([...schemas.map(schema => extractResolversFromSchema(schema)), ...(resolvers ? asArray(resolvers) : [])], config), resolversComposition || {}),
    schemaDirectives,
    resolverValidationOptions,
    logger,
  });
}

@kamilkisiela/graphql-tools

Useful tools to create and manipulate GraphQL schemas.

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis