graphql#lexicographicSortSchema TypeScript Examples

The following examples show how to use graphql#lexicographicSortSchema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: thrift-calculator.test.ts    From graphql-mesh with MIT License 6 votes vote down vote up
describe('Thrift Calculator', () => {
  it('should generate correct schema', async () => {
    const { schema } = await mesh$;
    expect(
      introspectionFromSchema(lexicographicSortSchema(schema), {
        descriptions: false,
      })
    ).toMatchSnapshot('thrift-calculator-schema');
  });
  it('should give correct response for example queries', async () => {
    const { documents } = await config$;
    const { execute } = await mesh$;
    for (const source of documents) {
      const result = await execute(source.document, {});
      expect(result.errors).toBeFalsy();
      expect(result).toMatchSnapshot(basename(source.location) + '-thrift-calculator-result');
    }
  });
  afterAll(() => {
    mesh$.then(mesh => mesh.destroy());
    thriftServer.close();
  });
});
Example #2
Source File: schemaTask.ts    From genql with MIT License 5 votes vote down vote up
schemaTask = (config: Config): ListrTask => {
    const processSchema = (schema) => {
        if (config.sortProperties) {
            return lexicographicSortSchema(schema)
        }
        return schema
    }

    if (config.endpoint) {
        const endpoint = config.endpoint
        return {
            title: `fetching schema using ${
                config.useGet ? 'GET' : 'POST'
            } ${endpoint} and headers ${JSON.stringify(config.headers)}`,
            task: async (ctx) => {
                ctx.schema = processSchema(
                    await fetchSchema({
                        endpoint,
                        usePost: !config.useGet,
                        headers: config.headers,
                    }),
                )
            },
        }
    } else if (config.schema) {
        const schema = config.schema
        return {
            title: 'loading schema',
            task: async (ctx) => {
                // const options = config.options && config.options.schemaBuild
                const document = await loadSchema(schema, {
                    loaders: [new GraphQLFileLoader()],
                })
                ctx.schema = processSchema(document)

                try {
                    assertValidSchema(ctx.schema)
                } catch (e) {
                    if (e.message === 'Query root type must be provided.')
                        return
                    throw e
                }
            },
        }
    } else {
        throw new Error(
            'either `endpoint`, `fetcher` or `schema` must be defined in the config',
        )
    }
}