summaryrefslogtreecommitdiff
path: root/src/utility/types.ts
blob: c96910cde2dd805f45939d8cd8eab4bd9d1a6a2d (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/// import

import type { GraphQLArgs, GraphQLSchema } from "npm:graphql@16.6.0";

/// util

import type { RenderPageOptions } from "../graphiql/render.ts";

interface MutationParams {
  mutation: string;
  operationName?: string;
  query?: never;
  variables?: Record<string, unknown>;
}

interface QueryParams {
  mutation?: never;
  operationName?: string;
  query: string;
  variables?: Record<string, unknown>;
}



/// export

export interface GQLOptions<Context = any, Req extends GQLRequest = GQLRequest> extends Omit<GraphQLArgs, "source"> {
  context?: (val: Req) => Context | Promise<Context>;
  /// GraphQL playground
  graphiql?: boolean;
  /// Custom headers for responses
  headers?: HeadersInit;
  /// Custom options for GraphQL Playground
  playgroundOptions?: Omit<RenderPageOptions, "endpoint">;
  schema: GraphQLSchema;
}

export type GraphQLParams = QueryParams | MutationParams;

export type GQLRequest = {
  headers: Headers;
  json: () => Promise<GraphQLParams>;
  method: string;
  url: string;
};