graphql#graphql TypeScript Examples
The following examples show how to use
graphql#graphql.
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: testGraphQLQuery.ts From Full-Stack-React-TypeScript-and-Node with MIT License | 6 votes |
testGraphQLQuery = async ({
schema,
source,
variableValues,
}: Options) => {
return graphql({
schema,
source,
variableValues,
});
}
Example #2
Source File: authentication.test.ts From graphql-mesh with MIT License | 6 votes |
test('Get patent using basic auth', () => {
const query = `{
viewerBasicAuth (username: "arlene123", password: "password123") {
patentWithId (patentId: "100") {
patentId
}
}
}`;
return graphql({
schema: createdSchema,
source: query,
}).then((result: any) => {
expect(result).toEqual({
data: {
viewerBasicAuth: {
patentWithId: {
patentId: '100',
},
},
},
});
});
});
Example #3
Source File: gcall.ts From convoychat with GNU General Public License v3.0 | 6 votes |
gCall = async ({
source,
variableValues,
currentUser,
}: Options) => {
if (!schema) {
schema = await createSchema();
}
return graphql(
schema,
source,
undefined,
createFakeContext(currentUser),
variableValues
);
}
Example #4
Source File: data_query_routes.ts From Deep-Lynx with MIT License | 6 votes |
// very simple route that passes the raw body directly to the the graphql query
// for the complex portions of this endpoint visit the data_query folder and functions
private static query(req: Request, res: Response, next: NextFunction) {
const generator = new GraphQLSchemaGenerator();
generator
.ForContainer(req.container?.id!, {
ontologyVersionID: req.query.ontologyVersionID as string,
returnFile: String(req.query.returnFile).toLowerCase() === 'true',
returnFileType: String(req.query.returnFileType).toLowerCase(),
})
.then((schemaResult) => {
if (schemaResult.isError) {
schemaResult.asResponse(res);
return;
}
graphql({
schema: schemaResult.value,
source: req.body.query,
variableValues: req.body.variables,
})
.then((response) => {
res.status(200).json(response);
})
.catch((e) => {
res.status(500).json(e.toString());
});
})
.catch((e) => {
res.status(500).json(e.toString());
});
}
Example #5
Source File: index.ts From fullstack-starterkit with MIT License | 6 votes |
private async graphqlRequest({ query, variables, context, operationName }: GraphQLRequest): Promise<any> {
const queryNode: DocumentNode = allQueries[operationName];
const queryNodeString: string = print(queryNode);
const source: string = query || queryNodeString;
const contextValue = (context = context ? { ...this.context, ...context } : this.context);
const { data, errors } = await graphql({ schema, source, variableValues: variables, contextValue });
if (errors && errors.length) {
throw errors[0];
}
if (!data) {
throw new Error(`Invalid query ${operationName}.`);
}
return data[operationName];
}
Example #6
Source File: getTestIntrospection.ts From ra-data-prisma with MIT License | 6 votes |
buildIntrospection = async (
rawSchema: GraphQLSchema,
options: CommonOptions,
) => {
const schema = await graphql(rawSchema, getIntrospectionQuery()).then(
({ data: { __schema } }) => __schema,
);
return introspection(null, {
...makeIntrospectionOptions({ ...options, ...defaultOurOptions }),
schema: schema,
}) as IntrospectionResult;
}
Example #7
Source File: render.ts From genql with MIT License | 6 votes |
toClientSchema = async (schemaGql: string) => {
const schema = buildSchema(schemaGql)
const introspectionResponse = await graphql(
schema,
getIntrospectionQuery(),
)
if (!introspectionResponse.data) {
throw new Error(JSON.stringify(introspectionResponse.errors))
}
return buildClientSchema(introspectionResponse.data as any)
}
Example #8
Source File: example_api.test.ts From graphql-mesh with MIT License | 5 votes |
test('Get descriptions', () => {
// Get all the descriptions of the fields on the GraphQL object type Car
const query = `{
__type(name: "Car") {
name
fields {
description
}
}
}`;
return graphql({ schema: createdSchema, source: query }).then((result: any) => {
expect(result).toEqual({
data: {
__type: {
name: 'Car',
fields: [
{
description: 'The color of the car.',
},
{
description: null,
},
{
description: null,
},
{
description: 'The model of the car.',
},
{
description: 'The rating of the car.',
},
{
description: 'Arbitrary (string) tags describing an entity.',
},
],
},
},
});
});
});