mirror of
https://github.com/directus/directus.git
synced 2026-01-27 08:28:20 -05:00
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
27 lines
718 B
TypeScript
27 lines
718 B
TypeScript
import request, { Response } from 'supertest';
|
|
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
|
|
|
|
export function processGraphQLJson(jsonQuery: any) {
|
|
return jsonToGraphQLQuery(jsonQuery);
|
|
}
|
|
|
|
export async function requestGraphQL(
|
|
host: string,
|
|
isSystemCollection: boolean,
|
|
token: string | null,
|
|
jsonQuery: any,
|
|
options?: { variables?: any; cookies?: string[] }
|
|
): Promise<Response> {
|
|
const req = request(host)
|
|
.post(isSystemCollection ? '/graphql/system' : '/graphql')
|
|
.send({
|
|
query: processGraphQLJson(jsonQuery),
|
|
variables: options?.variables,
|
|
});
|
|
|
|
if (token) req.set('Authorization', `Bearer ${token}`);
|
|
if (options?.cookies) req.set('Cookie', options.cookies);
|
|
|
|
return await req;
|
|
}
|