/
graphQL.ts
90 lines (80 loc) · 3.43 KB
/
graphQL.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as trace from "stack-trace";
import {
ingester as ingesterInternal,
IngesterOptions,
subscription as subscriptionInternal,
SubscriptionOptions,
} from "../internal/graph/graphQL";
export class ParameterEnum {
constructor(public value: string | string[]) {
}
}
export function enumValue(value: string | string[]): ParameterEnum {
return new ParameterEnum(value);
}
/**
* Prepare a GraphQL subscription string for the use with Apollo or EventHandlers.
*
* Subscription can be provided by the following options:
*
* * subscription: string containing the subscription GraphQL, or
* * path: absolute or relative path to a .graphql file to load; if provided a relative
* path this will resolve the relative path to an absolute given the location of
* the calling script.
* * name: name GraphQL subscription operation to load; this will walk up the directory
* structure starting at the location of the calling script and look for a folder
* called 'graphql'. Once that folder is found, the subscription named 'name' is
* being looked for.
* * fragmentsDir: location of fragment .graphql files
* * inline: remove any unneeded whitespace and line breaks from returned GraphQL string
* * variables: the variables to bind into the subscription
* * operationName: name of the subscription to use in the generated GraphQL string
*
* @param {{subscription?: string; path?: string; name?: string; fragmentDir?: string; inline?: boolean;
* variables?: {[p: string]: string | boolean | number | ParameterEnum}}} options
* @returns {string}
*/
export function subscription(optionsOrName: SubscriptionOptions | string): string {
const pathToCallingFunction = trace.get()[1].getFileName();
let options: SubscriptionOptions;
// Allow passing over a single string which would be the name of subscription file
if (typeof optionsOrName === "string") {
options = {
name: optionsOrName,
};
} else {
options = optionsOrName as SubscriptionOptions;
}
options.moduleDir = options.moduleDir || pathToCallingFunction;
return subscriptionInternal(options);
}
/**
* Prepare a GraphQL ingester SDL string for the register with the automation client.
*
* Ingester can be provided by the following options:
*
* * path: absolute or relative path to a .graphql file to load; if provided a relative
* path this will resolve the relative path to an absolute given the location of
* the calling script.
* * name: name of the .graphql file to load; this will walk up the directory structure
* starting a t the location of the calling script and look for a folder called
* 'graphql'. Once that folder is found, by convention name is being looked for
* in the 'ingester' sub directory.
*
* @param {IngesterOptions | string} optionsOrName
* @returns {string}
*/
export function ingester(optionsOrName: IngesterOptions | string): string {
const pathToCallingFunction = trace.get()[1].getFileName();
let options: IngesterOptions;
// Allow passing over a single string which would be the name of ingester file
if (typeof optionsOrName === "string") {
options = {
name: optionsOrName,
};
} else {
options = optionsOrName as IngesterOptions;
}
options.moduleDir = options.moduleDir || pathToCallingFunction;
return ingesterInternal(options);
}