-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathquery-builder.d.ts
86 lines (86 loc) · 4.53 KB
/
query-builder.d.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
import Model from "../orm/model";
import { Arguments, GraphQLField } from "../support/interfaces";
/**
* Contains all logic to build GraphQL queries/mutations.
*/
export default class QueryBuilder {
/**
* Builds a field for the GraphQL query and a specific model
*
* @param {Model|string} model The model to use
* @param {string} action Name of the current action like 'persist' or 'push'
* @param {boolean} multiple Determines whether plural/nodes syntax or singular syntax is used.
* @param {Arguments} args The args that will be passed to the query field ( user(role: $role) )
* @param {Array<Model>} path The relations in this list are ignored (while traversing relations).
* Mainly for recursion
* @param {string} name Optional name of the field. If not provided, this will be the model name
* @param filter
* @param {boolean} allowIdFields Optional. Determines if id fields will be ignored for the argument generation.
* See buildArguments
* @returns {string}
*
* @todo Do we need the allowIdFields param?
*/
static buildField(model: Model | string, action: string, multiple?: boolean, args?: Arguments, path?: Array<string>, name?: string, filter?: boolean, allowIdFields?: boolean): string;
/**
* Generates a query.
* Currently only one root field for the query is possible.
* @param {string} type 'mutation' or 'query'
* @param {Model | string} model The model this query or mutation affects. This mainly determines the query fields.
* @param {string} action Name of the current action like 'persist' or 'push'
* @param {string} name Optional name of the query/mutation. Will overwrite the name from the model.
* @param {Arguments} args Arguments for the query
* @param {boolean} multiple Determines if the root query field is a connection or not (will be passed to buildField)
* @param {boolean} filter When true the query arguments are passed via a filter object.
* @returns {any} Whatever gql() returns
*/
static buildQuery(type: string, model: Model | string, action: string, name?: string, args?: Arguments, multiple?: boolean, filter?: boolean): import("graphql").DocumentNode;
/**
* Generates the arguments string for a graphql query based on a given map.
*
* There are three types of arguments:
*
* 1) Signatures with primitive types (signature = true)
* => 'mutation createUser($name: String!)'
*
* 2) Signatures with object types (signature = true, args = { user: { __type: 'User' }})
* => 'mutation createUser($user: UserInput!)'
*
* 3) Fields with variables (signature = false)
* => 'user(id: $id)'
*
* 4) Filter fields with variables (signature = false, filter = true)
* => 'users(filter: { active: $active })'
*
* @param model
* @param {string} action Name of the current action like 'persist' or 'push'
* @param {Arguments | undefined} args
* @param {boolean} signature When true, then this method generates a query signature instead of key/value pairs
* @param filter
* @param {boolean} allowIdFields If true, ID fields will be included in the arguments list
* @param {GraphQLField} field Optional. The GraphQL mutation or query field
* @returns {String}
*/
static buildArguments(model: Model, action: string, args?: Arguments, signature?: boolean, filter?: boolean, allowIdFields?: boolean, field?: GraphQLField | null): string;
/**
* Determines the GraphQL primitive type of a field in the variables hash by the field type or (when
* the field type is generic attribute) by the variable type.
* @param {Model} model
* @param {string} key
* @param {string} value
* @param {GraphQLField} query Pass when we have to detect the type of an argument
* @returns {string}
*/
static determineAttributeType(model: Model, key: string, value: any, query?: GraphQLField): string;
private static findSchemaFieldForArgument;
/**
* Generates the fields for all related models.
*
* @param {Model} model
* @param {Array<Model>} path
* @param {string} action Name of the current action like 'persist' or 'push'
* @returns {string}
*/
static buildRelationsQuery(model: null | Model, path: string[] | undefined, action: string): string;
private static prepareArguments;
}