/** * Exports a PostGraphile schema by looking at a Postgres client. */ export default async function exportPostGraphileSchema( schema: GraphQLSchema, options: PostGraphileOptions = {}, ): Promise<void> { const jsonPath = typeof options.exportJsonSchemaPath === 'string' ? options.exportJsonSchemaPath : null; const graphqlPath = typeof options.exportGqlSchemaPath === 'string' ? options.exportGqlSchemaPath : null; // Sort schema, if requested const finalSchema = options.sortExport && lexicographicSortSchema && (jsonPath || graphqlPath) ? lexicographicSortSchema(schema) : schema; // JSON version if (jsonPath) { const result = await graphql(finalSchema, introspectionQuery); await writeFileIfDiffers(jsonPath, JSON.stringify(result, null, 2)); } // Schema language version if (graphqlPath) { await writeFileIfDiffers(graphqlPath, printSchema(finalSchema)); } }
return await graphql(gqlSchema, mutation, null, { [$$pgClient]: pgClient, });
: gqlSchemas.normal; return await graphql(gqlSchema, query, null, { [$$pgClient]: pgClient, });
const mockResponse = async (query, variableValues = {}) => { try { const res = await graphql({ schema, source: query.loc.source.body, variableValues, }); return res; } catch (error) { return error; } }
test('graphql.graphql', function (t) { resetAgent(done(t)) var schema = graphql.buildSchema('type Query { hello: String }') var root = { hello () { return 'Hello world!' } } var query = '{ hello }' agent.startTransaction('foo') graphql.graphql(schema, query, root).then(function (response) { agent.endTransaction() t.deepLooseEqual(response, { data: { hello: 'Hello world!' } }) agent.flush() }) })
test('graphql.graphql - transaction ended', function (t) { t.plan(5) resetAgent(1, function (data) { t.strictEqual(data.transactions.length, 1) t.strictEqual(data.spans.length, 0) var trans = data.transactions[0] t.strictEqual(trans.name, 'foo') t.strictEqual(trans.type, 'custom') }) var schema = graphql.buildSchema('type Query { hello: String }') var root = { hello () { return 'Hello world!' } } var query = '{ hello }' agent.startTransaction('foo').end() graphql.graphql(schema, query, root).then(function (response) { t.deepLooseEqual(response, { data: { hello: 'Hello world!' } }) }) })
test('graphql.graphql - invalid query', function (t) { resetAgent(done(t, 'Unknown Query')) var schema = graphql.buildSchema('type Query { hello: String }') var root = { hello () { return 'Hello world!' } } var query = '{ hello' agent.startTransaction('foo') graphql.graphql(schema, query, root).then(function (response) { agent.endTransaction() t.deepEqual(Object.keys(response), ['errors']) t.strictEqual(response.errors.length, 1, 'should have one error') t.ok(response.errors[0].message.indexOf('Syntax Error') !== -1, 'should return a sytax error') agent.flush() }) })