File size: 694 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { type ASTNode, print } from 'graphql';
import request from 'supertest';
import { isDefined } from 'twenty-shared/utils';

type GraphqlOperation = {
  query: ASTNode;
  variables?: Record<string, unknown>;
};

export const makeGraphqlAPIRequest = (
  graphqlOperation: GraphqlOperation,
  token: string | undefined = APPLE_JANE_ADMIN_ACCESS_TOKEN,
) => {
  const client = request(`http://localhost:${APP_PORT}`);

  const clientInstance = client.post('/graphql');

  if (isDefined(token)) {
    clientInstance.set('Authorization', `Bearer ${token}`);
  }

  return clientInstance.send({
    query: print(graphqlOperation.query),
    variables: graphqlOperation.variables || {},
  });
};