@contember/client-content 1.3.0-alpha.3 → 1.3.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/ContentClient.cjs +27 -0
- package/dist/development/ContentClient.cjs.map +1 -0
- package/dist/development/ContentClient.js +27 -0
- package/dist/development/ContentClient.js.map +1 -0
- package/dist/development/ContentQueryBuilder.cjs +147 -0
- package/dist/development/ContentQueryBuilder.cjs.map +1 -0
- package/dist/development/ContentQueryBuilder.js +147 -0
- package/dist/development/ContentQueryBuilder.js.map +1 -0
- package/dist/development/index.cjs +11 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +11 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/nodes/ContentEntitySelection.cjs +161 -0
- package/dist/development/nodes/ContentEntitySelection.cjs.map +1 -0
- package/dist/development/nodes/ContentEntitySelection.js +161 -0
- package/dist/development/nodes/ContentEntitySelection.js.map +1 -0
- package/dist/development/nodes/ContentOperation.cjs +16 -0
- package/dist/development/nodes/ContentOperation.cjs.map +1 -0
- package/dist/development/nodes/ContentOperation.js +16 -0
- package/dist/development/nodes/ContentOperation.js.map +1 -0
- package/dist/development/utils/ContentOperationSet.cjs +10 -0
- package/dist/development/utils/ContentOperationSet.cjs.map +1 -0
- package/dist/development/utils/ContentOperationSet.js +10 -0
- package/dist/development/utils/ContentOperationSet.js.map +1 -0
- package/dist/development/utils/createListArgs.cjs +24 -0
- package/dist/development/utils/createListArgs.cjs.map +1 -0
- package/dist/development/utils/createListArgs.js +24 -0
- package/dist/development/utils/createListArgs.js.map +1 -0
- package/dist/development/utils/createMutationOperationSet.cjs +37 -0
- package/dist/development/utils/createMutationOperationSet.cjs.map +1 -0
- package/dist/development/utils/createMutationOperationSet.js +37 -0
- package/dist/development/utils/createMutationOperationSet.js.map +1 -0
- package/dist/development/utils/createQueryOperationSet.cjs +19 -0
- package/dist/development/utils/createQueryOperationSet.cjs.map +1 -0
- package/dist/development/utils/createQueryOperationSet.js +19 -0
- package/dist/development/utils/createQueryOperationSet.js.map +1 -0
- package/dist/development/utils/createTypedArgs.cjs +14 -0
- package/dist/development/utils/createTypedArgs.cjs.map +1 -0
- package/dist/development/utils/createTypedArgs.js +14 -0
- package/dist/development/utils/createTypedArgs.js.map +1 -0
- package/dist/development/utils/mutationFragments.cjs +55 -0
- package/dist/development/utils/mutationFragments.cjs.map +1 -0
- package/dist/development/utils/mutationFragments.js +55 -0
- package/dist/development/utils/mutationFragments.js.map +1 -0
- package/dist/production/ContentClient.cjs +27 -0
- package/dist/production/ContentClient.cjs.map +1 -0
- package/dist/production/ContentClient.js +27 -0
- package/dist/production/ContentClient.js.map +1 -0
- package/dist/production/ContentQueryBuilder.cjs +147 -0
- package/dist/production/ContentQueryBuilder.cjs.map +1 -0
- package/dist/production/ContentQueryBuilder.js +147 -0
- package/dist/production/ContentQueryBuilder.js.map +1 -0
- package/dist/production/index.cjs +11 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +11 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/nodes/ContentEntitySelection.cjs +161 -0
- package/dist/production/nodes/ContentEntitySelection.cjs.map +1 -0
- package/dist/production/nodes/ContentEntitySelection.js +161 -0
- package/dist/production/nodes/ContentEntitySelection.js.map +1 -0
- package/dist/production/nodes/ContentOperation.cjs +16 -0
- package/dist/production/nodes/ContentOperation.cjs.map +1 -0
- package/dist/production/nodes/ContentOperation.js +16 -0
- package/dist/production/nodes/ContentOperation.js.map +1 -0
- package/dist/production/utils/ContentOperationSet.cjs +10 -0
- package/dist/production/utils/ContentOperationSet.cjs.map +1 -0
- package/dist/production/utils/ContentOperationSet.js +10 -0
- package/dist/production/utils/ContentOperationSet.js.map +1 -0
- package/dist/production/utils/createListArgs.cjs +24 -0
- package/dist/production/utils/createListArgs.cjs.map +1 -0
- package/dist/production/utils/createListArgs.js +24 -0
- package/dist/production/utils/createListArgs.js.map +1 -0
- package/dist/production/utils/createMutationOperationSet.cjs +37 -0
- package/dist/production/utils/createMutationOperationSet.cjs.map +1 -0
- package/dist/production/utils/createMutationOperationSet.js +37 -0
- package/dist/production/utils/createMutationOperationSet.js.map +1 -0
- package/dist/production/utils/createQueryOperationSet.cjs +19 -0
- package/dist/production/utils/createQueryOperationSet.cjs.map +1 -0
- package/dist/production/utils/createQueryOperationSet.js +19 -0
- package/dist/production/utils/createQueryOperationSet.js.map +1 -0
- package/dist/production/utils/createTypedArgs.cjs +14 -0
- package/dist/production/utils/createTypedArgs.cjs.map +1 -0
- package/dist/production/utils/createTypedArgs.js +14 -0
- package/dist/production/utils/createTypedArgs.js.map +1 -0
- package/dist/production/utils/mutationFragments.cjs +55 -0
- package/dist/production/utils/mutationFragments.cjs.map +1 -0
- package/dist/production/utils/mutationFragments.js +55 -0
- package/dist/production/utils/mutationFragments.js.map +1 -0
- package/dist/types/ContentQueryBuilder.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/Input.d.ts +2 -2
- package/dist/types/types/Input.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/ContentQueryBuilder.ts +6 -2
- package/src/types/Input.ts +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutationFragments.js","sources":["../../../src/utils/mutationFragments.ts"],"sourcesContent":["import { GraphQlField, GraphQlFragment, GraphQlFragmentSpread, GraphQlInlineFragment } from '@contember/graphql-builder'\n\nexport const mutationFragments: Record<string, GraphQlFragment> = {\n\tMutationError: new GraphQlFragment('MutationError', '_MutationError', [\n\t\tnew GraphQlField(null, 'paths', {}, [\n\t\t\tnew GraphQlInlineFragment('_FieldPathFragment', [\n\t\t\t\tnew GraphQlField(null, 'field'),\n\t\t\t]),\n\t\t\tnew GraphQlInlineFragment('_IndexPathFragment', [\n\t\t\t\tnew GraphQlField(null, 'index'),\n\t\t\t\tnew GraphQlField(null, 'alias'),\n\t\t\t]),\n\t\t]),\n\t\tnew GraphQlField(null, 'message'),\n\t\tnew GraphQlField(null, 'type'),\n\t]),\n\tTransactionResult: new GraphQlFragment('TransactionResult', 'TransactionResult', [\n\t\tnew GraphQlField(null, 'ok'),\n\t\tnew GraphQlField(null, 'errorMessage'),\n\t\tnew GraphQlField(null, 'errors', {}, [\n\t\t\tnew GraphQlField(null, 'paths', {}, [\n\t\t\t\tnew GraphQlInlineFragment('_FieldPathFragment', [\n\t\t\t\t\tnew GraphQlField(null, 'field'),\n\t\t\t\t]),\n\t\t\t\tnew GraphQlInlineFragment('_IndexPathFragment', [\n\t\t\t\t\tnew GraphQlField(null, 'index'),\n\t\t\t\t\tnew GraphQlField(null, 'alias'),\n\t\t\t\t]),\n\t\t\t]),\n\t\t]),\n\t\tnew GraphQlField(null, 'validation', {}, [\n\t\t\tnew GraphQlFragmentSpread('ValidationResult'),\n\t\t]),\n\t]),\n\tValidationResult: new GraphQlFragment('ValidationResult', '_ValidationResult', [\n\t\tnew GraphQlField(null, 'valid'),\n\t\tnew GraphQlField(null, 'errors', {}, [\n\t\t\tnew GraphQlField(null, 'path', {}, [\n\t\t\t\tnew GraphQlInlineFragment('_FieldPathFragment', [\n\t\t\t\t\tnew GraphQlField(null, 'field'),\n\t\t\t\t]),\n\t\t\t\tnew GraphQlInlineFragment('_IndexPathFragment', [\n\t\t\t\t\tnew GraphQlField(null, 'index'),\n\t\t\t\t\tnew GraphQlField(null, 'alias'),\n\t\t\t\t]),\n\t\t\t]),\n\t\t\tnew GraphQlField(null, 'message', {}, [\n\t\t\t\tnew GraphQlField(null, 'text'),\n\t\t\t]),\n\t\t]),\n\t]),\n}\n"],"names":[],"mappings":";AAEO,MAAM,oBAAqD;AAAA,EACjE,eAAe,IAAI,gBAAgB,iBAAiB,kBAAkB;AAAA,IACrE,IAAI,aAAa,MAAM,SAAS,IAAI;AAAA,MACnC,IAAI,sBAAsB,sBAAsB;AAAA,QAC/C,IAAI,aAAa,MAAM,OAAO;AAAA,MAAA,CAC9B;AAAA,MACD,IAAI,sBAAs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AI;AAAA,QACrC,IAAI,aAAa,MAAM,MAAM;AAAA,MAAA,CAC7B;AAAA,IAAA,CACD;AAAA,EAAA,CACD;AACF;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const mutationFragments = require("./utils/mutationFragments.cjs");
|
|
4
|
+
const graphqlBuilder = require("@contember/graphql-builder");
|
|
5
|
+
const createMutationOperationSet = require("./utils/createMutationOperationSet.cjs");
|
|
6
|
+
const createQueryOperationSet = require("./utils/createQueryOperationSet.cjs");
|
|
7
|
+
class ContentClient {
|
|
8
|
+
constructor(executor) {
|
|
9
|
+
this.executor = executor;
|
|
10
|
+
}
|
|
11
|
+
async query(queries, options) {
|
|
12
|
+
const printer = new graphqlBuilder.GraphQlQueryPrinter();
|
|
13
|
+
const operationSet = createQueryOperationSet.createQueryOperationSet(queries);
|
|
14
|
+
const { query, variables } = printer.printDocument("query", operationSet.selection, {});
|
|
15
|
+
const result = await this.executor(query, { variables, ...options });
|
|
16
|
+
return operationSet.parse(result);
|
|
17
|
+
}
|
|
18
|
+
async mutate(input, options) {
|
|
19
|
+
const operationSet = createMutationOperationSet.createMutationOperationSet(input);
|
|
20
|
+
const printer = new graphqlBuilder.GraphQlQueryPrinter();
|
|
21
|
+
const { query, variables } = printer.printDocument("mutation", operationSet.selection, mutationFragments.mutationFragments);
|
|
22
|
+
const result = await this.executor(query, { variables, ...options });
|
|
23
|
+
return operationSet.parse(result);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ContentClient = ContentClient;
|
|
27
|
+
//# sourceMappingURL=ContentClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentClient.cjs","sources":["../../src/ContentClient.ts"],"sourcesContent":["import { mutationFragments } from './utils/mutationFragments'\nimport { GraphQlClientRequestOptions } from '@contember/graphql-client'\nimport { GraphQlQueryPrinter } from '@contember/graphql-builder'\nimport { ContentMutation, ContentQuery } from './nodes'\nimport { createMutationOperationSet } from './utils/createMutationOperationSet'\nimport { createQueryOperationSet } from './utils/createQueryOperationSet'\n\n\nexport type QueryExecutorOptions = GraphQlClientRequestOptions\n\nexport type QueryExecutor = <T = unknown>(query: string, options: GraphQlClientRequestOptions) => Promise<T>\n\nexport class ContentClient {\n\tconstructor(\n\t\tprivate readonly executor: QueryExecutor,\n\t) {\n\t}\n\n\n\tpublic async query<Value>(query: ContentQuery<Value>, options?: QueryExecutorOptions): Promise<Value>\n\tpublic async query<Values extends Record<string, any>>(queries: {[K in keyof Values]: ContentQuery<Values[K]>}, options?: QueryExecutorOptions): Promise<Values>\n\tpublic async query(queries: Record<string, ContentQuery<any>> | ContentQuery<any>, options?: QueryExecutorOptions): Promise<any> {\n\t\tconst printer = new GraphQlQueryPrinter()\n\t\tconst operationSet = createQueryOperationSet(queries)\n\t\tconst { query, variables } = printer.printDocument('query', operationSet.selection, {})\n\t\tconst result = await this.executor(query, { variables, ...options })\n\t\treturn operationSet.parse(result)\n\t}\n\n\tpublic async mutate<Value>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions,): Promise<Value>\n\tpublic async mutate<Value>(mutations: ContentMutation<Value>[], options?: QueryExecutorOptions,): Promise<Value[]>\n\tpublic async mutate<Values extends Record<string, any>>(mutations: { [K in keyof Values]: ContentMutation<Values[K]> | ContentQuery<Values[K]> }, options?: QueryExecutorOptions): Promise<Values>\n\tpublic async mutate(input: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[], options?: QueryExecutorOptions): Promise<any> {\n\t\tconst operationSet = createMutationOperationSet(input)\n\n\t\tconst printer = new GraphQlQueryPrinter()\n\t\tconst { query, variables } = printer.printDocument('mutation', operationSet.selection, mutationFragments)\n\t\tconst result = await this.executor(query, { variables, ...options })\n\n\t\treturn operationSet.parse(result)\n\t}\n}\n"],"names":["GraphQlQueryPrinter","createQueryOperationSet","createMutationOperationSet","mutationFragments"],"mappings":";;;;;;AAYO,MAAM,cAAc;AAAA,EAC1B,YACkB,UAChB;AADgB,SAAA,WAAA;AAAA,EAElB;AAAA,EAKA,MAAa,MAAM,SAAgE,SAA8C;AAC1H,UAAA,UAAU,IAAIA,eAAAA;AACd,UAAA,eAAeC,gDAAwB,OAAO;AAC9C,UAAA,EAAE,OAAO,UAAA,IAAc,QAAQ,cAAc,SAAS,aAAa,WAAW,CAAA,CAAE;AAChF,UAAA,SAAS,MAAM,KAAK,SAAS,OAAO,EAAE,WAAW,GAAG,QAAA,CAAS;AAC5D,WAAA,aAAa,MAAM,MAAM;AAAA,EACjC;AAAA,EAKA,MAAa,OAAO,OAAiH,SAA8C;AAC5K,UAAA,eAAeC,sDAA2B,KAAK;AAE/C,UAAA,UAAU,IAAIF,eAAAA;AACd,UAAA,EAAE,OAAO,UAAU,IAAI,QAAQ,cAAc,YAAY,aAAa,WAAWG,kBAAAA,iBAAiB;AAClG,UAAA,SAAS,MAAM,KAAK,SAAS,OAAO,EAAE,WAAW,GAAG,QAAA,CAAS;AAE5D,WAAA,aAAa,MAAM,MAAM;AAAA,EACjC;AACD;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mutationFragments } from "./utils/mutationFragments.js";
|
|
2
|
+
import { GraphQlQueryPrinter } from "@contember/graphql-builder";
|
|
3
|
+
import { createMutationOperationSet } from "./utils/createMutationOperationSet.js";
|
|
4
|
+
import { createQueryOperationSet } from "./utils/createQueryOperationSet.js";
|
|
5
|
+
class ContentClient {
|
|
6
|
+
constructor(executor) {
|
|
7
|
+
this.executor = executor;
|
|
8
|
+
}
|
|
9
|
+
async query(queries, options) {
|
|
10
|
+
const printer = new GraphQlQueryPrinter();
|
|
11
|
+
const operationSet = createQueryOperationSet(queries);
|
|
12
|
+
const { query, variables } = printer.printDocument("query", operationSet.selection, {});
|
|
13
|
+
const result = await this.executor(query, { variables, ...options });
|
|
14
|
+
return operationSet.parse(result);
|
|
15
|
+
}
|
|
16
|
+
async mutate(input, options) {
|
|
17
|
+
const operationSet = createMutationOperationSet(input);
|
|
18
|
+
const printer = new GraphQlQueryPrinter();
|
|
19
|
+
const { query, variables } = printer.printDocument("mutation", operationSet.selection, mutationFragments);
|
|
20
|
+
const result = await this.executor(query, { variables, ...options });
|
|
21
|
+
return operationSet.parse(result);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
ContentClient
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=ContentClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentClient.js","sources":["../../src/ContentClient.ts"],"sourcesContent":["import { mutationFragments } from './utils/mutationFragments'\nimport { GraphQlClientRequestOptions } from '@contember/graphql-client'\nimport { GraphQlQueryPrinter } from '@contember/graphql-builder'\nimport { ContentMutation, ContentQuery } from './nodes'\nimport { createMutationOperationSet } from './utils/createMutationOperationSet'\nimport { createQueryOperationSet } from './utils/createQueryOperationSet'\n\n\nexport type QueryExecutorOptions = GraphQlClientRequestOptions\n\nexport type QueryExecutor = <T = unknown>(query: string, options: GraphQlClientRequestOptions) => Promise<T>\n\nexport class ContentClient {\n\tconstructor(\n\t\tprivate readonly executor: QueryExecutor,\n\t) {\n\t}\n\n\n\tpublic async query<Value>(query: ContentQuery<Value>, options?: QueryExecutorOptions): Promise<Value>\n\tpublic async query<Values extends Record<string, any>>(queries: {[K in keyof Values]: ContentQuery<Values[K]>}, options?: QueryExecutorOptions): Promise<Values>\n\tpublic async query(queries: Record<string, ContentQuery<any>> | ContentQuery<any>, options?: QueryExecutorOptions): Promise<any> {\n\t\tconst printer = new GraphQlQueryPrinter()\n\t\tconst operationSet = createQueryOperationSet(queries)\n\t\tconst { query, variables } = printer.printDocument('query', operationSet.selection, {})\n\t\tconst result = await this.executor(query, { variables, ...options })\n\t\treturn operationSet.parse(result)\n\t}\n\n\tpublic async mutate<Value>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions,): Promise<Value>\n\tpublic async mutate<Value>(mutations: ContentMutation<Value>[], options?: QueryExecutorOptions,): Promise<Value[]>\n\tpublic async mutate<Values extends Record<string, any>>(mutations: { [K in keyof Values]: ContentMutation<Values[K]> | ContentQuery<Values[K]> }, options?: QueryExecutorOptions): Promise<Values>\n\tpublic async mutate(input: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[], options?: QueryExecutorOptions): Promise<any> {\n\t\tconst operationSet = createMutationOperationSet(input)\n\n\t\tconst printer = new GraphQlQueryPrinter()\n\t\tconst { query, variables } = printer.printDocument('mutation', operationSet.selection, mutationFragments)\n\t\tconst result = await this.executor(query, { variables, ...options })\n\n\t\treturn operationSet.parse(result)\n\t}\n}\n"],"names":[],"mappings":";;;;AAYO,MAAM,cAAc;AAAA,EAC1B,YACkB,UAChB;AADgB,SAAA,WAAA;AAAA,EAElB;AAAA,EAKA,MAAa,MAAM,SAAgE,SAA8C;AAC1H,UAAA,UAAU,IAAI;AACd,UAAA,eAAe,wBAAwB,OAAO;AAC9C,UAAA,EAAE,OAAO,UAAA,IAAc,QAAQ,cAAc,SAAS,aAAa,WAAW,CAAA,CAAE;AAChF,UAAA,SAAS,MAAM,KAAK,SAAS,OAAO,EAAE,WAAW,GAAG,QAAA,CAAS;AAC5D,WAAA,aAAa,MAAM,MAAM;AAAA,EACjC;AAAA,EAKA,MAAa,OAAO,OAAiH,SAA8C;AAC5K,UAAA,eAAe,2BAA2B,KAAK;AAE/C,UAAA,UAAU,IAAI;AACd,UAAA,EAAE,OAAO,UAAU,IAAI,QAAQ,cAAc,YAAY,aAAa,WAAW,iBAAiB;AAClG,UAAA,SAAS,MAAM,KAAK,SAAS,OAAO,EAAE,WAAW,GAAG,QAAA,CAAS;AAE5D,WAAA,aAAa,MAAM,MAAM;AAAA,EACjC;AACD;"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createListArgs = require("./utils/createListArgs.cjs");
|
|
4
|
+
const createTypedArgs = require("./utils/createTypedArgs.cjs");
|
|
5
|
+
const graphqlBuilder = require("@contember/graphql-builder");
|
|
6
|
+
const createMutationOperationSet = require("./utils/createMutationOperationSet.cjs");
|
|
7
|
+
const ContentEntitySelection = require("./nodes/ContentEntitySelection.cjs");
|
|
8
|
+
const ContentOperation = require("./nodes/ContentOperation.cjs");
|
|
9
|
+
class ContentQueryBuilder {
|
|
10
|
+
constructor(schema) {
|
|
11
|
+
this.schema = schema;
|
|
12
|
+
}
|
|
13
|
+
fragment(name, fieldsCallback) {
|
|
14
|
+
const context = this.createContext(name);
|
|
15
|
+
const entitySelection = new ContentEntitySelection.ContentEntitySelection(context, []);
|
|
16
|
+
if (!fieldsCallback) {
|
|
17
|
+
return entitySelection;
|
|
18
|
+
}
|
|
19
|
+
return fieldsCallback(entitySelection);
|
|
20
|
+
}
|
|
21
|
+
count(name, args) {
|
|
22
|
+
const context = this.createContext(name);
|
|
23
|
+
const fieldName = `paginate${name}`;
|
|
24
|
+
const typedArgs = createTypedArgs.createTypedArgs(args, {
|
|
25
|
+
filter: `${context.entity.name}Where`
|
|
26
|
+
});
|
|
27
|
+
const selectionSet = [
|
|
28
|
+
new graphqlBuilder.GraphQlField(null, "pageInfo", {}, [
|
|
29
|
+
new graphqlBuilder.GraphQlField(null, "totalCount")
|
|
30
|
+
])
|
|
31
|
+
];
|
|
32
|
+
return new ContentOperation.ContentOperation("query", fieldName, typedArgs, selectionSet, (it) => {
|
|
33
|
+
return it.pageInfo.totalCount;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
list(name, args, fields) {
|
|
37
|
+
const context = this.createContext(name);
|
|
38
|
+
const fieldName = `list${name}`;
|
|
39
|
+
const typedArgs = createListArgs.createListArgs(context.entity, args);
|
|
40
|
+
const selectionSet = this.resolveSelectionSet(fields, context);
|
|
41
|
+
return new ContentOperation.ContentOperation("query", fieldName, typedArgs, selectionSet);
|
|
42
|
+
}
|
|
43
|
+
get(name, args, fields) {
|
|
44
|
+
const context = this.createContext(name);
|
|
45
|
+
const fieldName = `get${name}`;
|
|
46
|
+
const typedArgs = createTypedArgs.createTypedArgs(args, {
|
|
47
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
48
|
+
filter: `${context.entity.name}Where`
|
|
49
|
+
});
|
|
50
|
+
const selectionSet = this.resolveSelectionSet(fields, context);
|
|
51
|
+
return new ContentOperation.ContentOperation("query", fieldName, typedArgs, selectionSet);
|
|
52
|
+
}
|
|
53
|
+
create(name, args, fields) {
|
|
54
|
+
const context = this.createContext(name);
|
|
55
|
+
const fieldName = `create${name}`;
|
|
56
|
+
const typedArgs = createTypedArgs.createTypedArgs(args, {
|
|
57
|
+
data: `${context.entity.name}CreateInput!`
|
|
58
|
+
});
|
|
59
|
+
const selectionSet = this.createMutationSelection("create", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
60
|
+
return new ContentOperation.ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
61
|
+
}
|
|
62
|
+
update(name, args, fields) {
|
|
63
|
+
const context = this.createContext(name);
|
|
64
|
+
const fieldName = `update${name}`;
|
|
65
|
+
const typedArgs = createTypedArgs.createTypedArgs(args, {
|
|
66
|
+
data: `${context.entity.name}UpdateInput!`,
|
|
67
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
68
|
+
filter: `${context.entity.name}Where`
|
|
69
|
+
});
|
|
70
|
+
const selectionSet = this.createMutationSelection("update", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
71
|
+
return new ContentOperation.ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
72
|
+
}
|
|
73
|
+
upsert(name, args, fields) {
|
|
74
|
+
const context = this.createContext(name);
|
|
75
|
+
const fieldName = `upsert${name}`;
|
|
76
|
+
const typedArgs = createTypedArgs.createTypedArgs(args, {
|
|
77
|
+
update: `${context.entity.name}UpdateInput!`,
|
|
78
|
+
create: `${context.entity.name}CreateInput!`,
|
|
79
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
80
|
+
filter: `${context.entity.name}Where`
|
|
81
|
+
});
|
|
82
|
+
const selectionSet = this.createMutationSelection("upsert", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
83
|
+
return new ContentOperation.ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
84
|
+
}
|
|
85
|
+
delete(name, args, fields) {
|
|
86
|
+
const context = this.createContext(name);
|
|
87
|
+
const typedArgs = createTypedArgs.createTypedArgs(args, {
|
|
88
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
89
|
+
filter: `${context.entity.name}Where`
|
|
90
|
+
});
|
|
91
|
+
const fieldName = `delete${name}`;
|
|
92
|
+
const selectionSet = this.createMutationSelection("delete", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
93
|
+
return new ContentOperation.ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
94
|
+
}
|
|
95
|
+
transaction(input, options = {}) {
|
|
96
|
+
const combined = createMutationOperationSet.createMutationOperationSet(input);
|
|
97
|
+
const transactionArgs = createTypedArgs.createTypedArgs({ options }, {
|
|
98
|
+
options: "MutationTransactionOptions"
|
|
99
|
+
});
|
|
100
|
+
const items = [
|
|
101
|
+
...this.createMutationSelection("transaction"),
|
|
102
|
+
...combined.selection
|
|
103
|
+
];
|
|
104
|
+
return new ContentOperation.ContentOperation("mutation", "transaction", transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {
|
|
105
|
+
return {
|
|
106
|
+
ok,
|
|
107
|
+
errorMessage,
|
|
108
|
+
errors,
|
|
109
|
+
validation,
|
|
110
|
+
data: combined.parse(data)
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
createMutationSelection(operation, selection) {
|
|
115
|
+
const items = [
|
|
116
|
+
new graphqlBuilder.GraphQlField(null, "ok"),
|
|
117
|
+
new graphqlBuilder.GraphQlField(null, "errorMessage"),
|
|
118
|
+
new graphqlBuilder.GraphQlField(null, "errors", {}, [
|
|
119
|
+
new graphqlBuilder.GraphQlFragmentSpread("MutationError")
|
|
120
|
+
])
|
|
121
|
+
];
|
|
122
|
+
if (operation !== "delete") {
|
|
123
|
+
items.push(new graphqlBuilder.GraphQlField(null, "validation", {}, [
|
|
124
|
+
new graphqlBuilder.GraphQlFragmentSpread("ValidationResult")
|
|
125
|
+
]));
|
|
126
|
+
}
|
|
127
|
+
if (selection) {
|
|
128
|
+
items.push(new graphqlBuilder.GraphQlField(null, "node", {}, selection));
|
|
129
|
+
}
|
|
130
|
+
return items;
|
|
131
|
+
}
|
|
132
|
+
resolveSelectionSet(fields, context) {
|
|
133
|
+
return (typeof fields === "function" ? fields(new ContentEntitySelection.ContentEntitySelection(context, [])) : fields).selectionSet;
|
|
134
|
+
}
|
|
135
|
+
createContext(name) {
|
|
136
|
+
const entity = this.schema.entities[name];
|
|
137
|
+
if (!entity) {
|
|
138
|
+
throw new Error(`Entity ${name} not found`);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
entity,
|
|
142
|
+
schema: this.schema
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.ContentQueryBuilder = ContentQueryBuilder;
|
|
147
|
+
//# sourceMappingURL=ContentQueryBuilder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentQueryBuilder.cjs","sources":["../../src/ContentQueryBuilder.ts"],"sourcesContent":["import { ContentClientInput, MutationResult, SchemaNames, TransactionResult } from './types'\nimport {\n\tContentEntitySelection,\n\tContentEntitySelectionCallback,\n\tContentEntitySelectionContext,\n\tContentMutation,\n\tContentOperation,\n\tContentQuery,\n} from './nodes'\nimport { createListArgs } from './utils/createListArgs'\nimport { createTypedArgs } from './utils/createTypedArgs'\nimport { Input } from '@contember/schema'\nimport { GraphQlField, GraphQlFragmentSpread, GraphQlSelectionSet } from '@contember/graphql-builder'\nimport { createMutationOperationSet } from './utils/createMutationOperationSet'\n\nexport type EntitySelectionOrCallback =\n\t| ContentEntitySelection\n\t| ContentEntitySelectionCallback\n\nexport type MutationTransactionOptions = {\n\tdeferForeignKeyConstraints?: boolean\n\tdeferUniqueConstraints?: boolean\n}\n\nexport class ContentQueryBuilder {\n\tconstructor(private readonly schema: SchemaNames) {\n\t}\n\n\n\tpublic fragment(name: string, fieldsCallback?: ContentEntitySelectionCallback): ContentEntitySelection {\n\t\tconst context = this.createContext(name)\n\n\t\tconst entitySelection = new ContentEntitySelection(context, [])\n\t\tif (!fieldsCallback) {\n\t\t\treturn entitySelection\n\t\t}\n\t\treturn fieldsCallback(entitySelection)\n\t}\n\n\n\n\tpublic count(name: string, args: Pick<ContentClientInput.AnyListQueryInput, 'filter'>): ContentQuery<number> {\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `paginate${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst selectionSet: GraphQlSelectionSet = [\n\t\t\tnew GraphQlField(null, 'pageInfo', {}, [\n\t\t\t\tnew GraphQlField(null, 'totalCount'),\n\t\t\t]),\n\t\t]\n\n\t\treturn new ContentOperation('query', fieldName, typedArgs, selectionSet, it => {\n\t\t\treturn it.pageInfo.totalCount\n\t\t})\n\t}\n\n\n\tpublic list(name: string, args: ContentClientInput.AnyListQueryInput, fields: EntitySelectionOrCallback): ContentQuery<any[]> {\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `list${name}`\n\t\tconst typedArgs = createListArgs(context.entity, args)\n\t\tconst selectionSet = this.resolveSelectionSet(fields, context)\n\n\t\treturn new ContentOperation('query', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic get(name: string, args: Input.UniqueQueryInput, fields: EntitySelectionOrCallback): ContentQuery<Record<string, unknown> | null> {\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `get${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst selectionSet = this.resolveSelectionSet(fields, context)\n\n\t\treturn new ContentOperation('query', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic create(name: string, args: Input.CreateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `create${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tdata: `${context.entity.name}CreateInput!`,\n\t\t})\n\t\tconst selectionSet = this.createMutationSelection('create', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic update(name: string, args: Input.UpdateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `update${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tdata: `${context.entity.name}UpdateInput!`,\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst selectionSet = this.createMutationSelection('update', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic upsert(name: string, args: Input.UpsertInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `upsert${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tupdate: `${context.entity.name}UpdateInput!`,\n\t\t\tcreate: `${context.entity.name}CreateInput!`,\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\n\t\tconst selectionSet = this.createMutationSelection('upsert', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic delete(name: string, args: Input.UniqueQueryInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst fieldName = `delete${name}`\n\t\tconst selectionSet = this.createMutationSelection('delete', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\tpublic transaction(\n\t\tinput: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[],\n\t\toptions: MutationTransactionOptions = {},\n\t): ContentMutation<TransactionResult<any>> {\n\t\tconst combined = createMutationOperationSet(input)\n\n\t\tconst transactionArgs = createTypedArgs({ options }, {\n\t\t\toptions: 'MutationTransactionOptions',\n\t\t})\n\t\tconst items = [\n\t\t\t...this.createMutationSelection('transaction'),\n\t\t\t...combined.selection,\n\t\t]\n\t\treturn new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {\n\t\t\treturn {\n\t\t\t\tok,\n\t\t\t\terrorMessage,\n\t\t\t\terrors,\n\t\t\t\tvalidation,\n\t\t\t\tdata: combined.parse(data),\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate createMutationSelection(operation: 'create' | 'update' | 'delete' | 'upsert' | 'transaction', selection?: GraphQlSelectionSet): GraphQlSelectionSet {\n\t\tconst items: GraphQlSelectionSet = [\n\t\t\tnew GraphQlField(null, 'ok'),\n\t\t\tnew GraphQlField(null, 'errorMessage'),\n\t\t\tnew GraphQlField(null, 'errors', {}, [\n\t\t\t\tnew GraphQlFragmentSpread('MutationError'),\n\t\t\t]),\n\t\t]\n\t\tif (operation !== 'delete') {\n\t\t\titems.push(new GraphQlField(null, 'validation', {}, [\n\t\t\t\tnew GraphQlFragmentSpread('ValidationResult'),\n\t\t\t]))\n\t\t}\n\t\tif (selection) {\n\t\t\titems.push(new GraphQlField(null, 'node', {}, selection))\n\t\t}\n\t\treturn items\n\t}\n\n\n\tprivate resolveSelectionSet(\n\t\tfields: EntitySelectionOrCallback,\n\t\tcontext: ContentEntitySelectionContext<string>,\n\t) {\n\t\treturn (typeof fields === 'function' ? fields(new ContentEntitySelection(context, [])) : fields).selectionSet\n\t}\n\n\tprivate createContext(\n\t\tname: string,\n\t): ContentEntitySelectionContext<string> {\n\t\tconst entity = this.schema.entities[name]\n\t\tif (!entity) {\n\t\t\tthrow new Error(`Entity ${name} not found`)\n\t\t}\n\t\treturn {\n\t\t\tentity: entity,\n\t\t\tschema: this.schema,\n\t\t}\n\t}\n}\n"],"names":["ContentEntitySelection","createTypedArgs","GraphQlField","ContentOperation","createListArgs","createMutationOperationSet","GraphQlFragmentSpread"],"mappings":";;;;;;;;AAwBO,MAAM,oBAAoB;AAAA,EAChC,YAA6B,QAAqB;AAArB,SAAA,SAAA;AAAA,EAC7B;AAAA,EAGO,SAAS,MAAc,gBAAyE;AAChG,UAAA,UAAU,KAAK,cAAc,IAAI;AAEvC,UAAM,kBAAkB,IAAIA,uBAAAA,uBAAuB,SAAS,CAAE,CAAA;AAC9D,QAAI,CAAC,gBAAgB;AACb,aAAA;AAAA,IACR;AACA,WAAO,eAAe,eAAe;AAAA,EACtC;AAAA,EAIO,MAAM,MAAc,MAAkF;AACtG,UAAA,UAAU,KAAK,cAAc,IAAI;AACvC,UAAM,YAAY,WAAW;AACvB,UAAA,YAAYC,gCAAgB,MAAM;AAAA,MACvC,QAAQ,GAAG,QAAQ,OAAO;AAAA,IAAA,CAC1B;AACD,UAAM,eAAoC;AAAA,MACzC,IAAIC,4BAAa,MAAM,YAAY,IAAI;AAAA,QACtC,IAAIA,eAAa,aAAA,MAAM,YAAY;AAAA,MAAA,CACnC;AAAA,IAAA;AAGF,WAAO,IAAIC,iBAAiB,iBAAA,S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D;;"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { createListArgs } from "./utils/createListArgs.js";
|
|
2
|
+
import { createTypedArgs } from "./utils/createTypedArgs.js";
|
|
3
|
+
import { GraphQlField, GraphQlFragmentSpread } from "@contember/graphql-builder";
|
|
4
|
+
import { createMutationOperationSet } from "./utils/createMutationOperationSet.js";
|
|
5
|
+
import { ContentEntitySelection } from "./nodes/ContentEntitySelection.js";
|
|
6
|
+
import { ContentOperation } from "./nodes/ContentOperation.js";
|
|
7
|
+
class ContentQueryBuilder {
|
|
8
|
+
constructor(schema) {
|
|
9
|
+
this.schema = schema;
|
|
10
|
+
}
|
|
11
|
+
fragment(name, fieldsCallback) {
|
|
12
|
+
const context = this.createContext(name);
|
|
13
|
+
const entitySelection = new ContentEntitySelection(context, []);
|
|
14
|
+
if (!fieldsCallback) {
|
|
15
|
+
return entitySelection;
|
|
16
|
+
}
|
|
17
|
+
return fieldsCallback(entitySelection);
|
|
18
|
+
}
|
|
19
|
+
count(name, args) {
|
|
20
|
+
const context = this.createContext(name);
|
|
21
|
+
const fieldName = `paginate${name}`;
|
|
22
|
+
const typedArgs = createTypedArgs(args, {
|
|
23
|
+
filter: `${context.entity.name}Where`
|
|
24
|
+
});
|
|
25
|
+
const selectionSet = [
|
|
26
|
+
new GraphQlField(null, "pageInfo", {}, [
|
|
27
|
+
new GraphQlField(null, "totalCount")
|
|
28
|
+
])
|
|
29
|
+
];
|
|
30
|
+
return new ContentOperation("query", fieldName, typedArgs, selectionSet, (it) => {
|
|
31
|
+
return it.pageInfo.totalCount;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
list(name, args, fields) {
|
|
35
|
+
const context = this.createContext(name);
|
|
36
|
+
const fieldName = `list${name}`;
|
|
37
|
+
const typedArgs = createListArgs(context.entity, args);
|
|
38
|
+
const selectionSet = this.resolveSelectionSet(fields, context);
|
|
39
|
+
return new ContentOperation("query", fieldName, typedArgs, selectionSet);
|
|
40
|
+
}
|
|
41
|
+
get(name, args, fields) {
|
|
42
|
+
const context = this.createContext(name);
|
|
43
|
+
const fieldName = `get${name}`;
|
|
44
|
+
const typedArgs = createTypedArgs(args, {
|
|
45
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
46
|
+
filter: `${context.entity.name}Where`
|
|
47
|
+
});
|
|
48
|
+
const selectionSet = this.resolveSelectionSet(fields, context);
|
|
49
|
+
return new ContentOperation("query", fieldName, typedArgs, selectionSet);
|
|
50
|
+
}
|
|
51
|
+
create(name, args, fields) {
|
|
52
|
+
const context = this.createContext(name);
|
|
53
|
+
const fieldName = `create${name}`;
|
|
54
|
+
const typedArgs = createTypedArgs(args, {
|
|
55
|
+
data: `${context.entity.name}CreateInput!`
|
|
56
|
+
});
|
|
57
|
+
const selectionSet = this.createMutationSelection("create", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
58
|
+
return new ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
59
|
+
}
|
|
60
|
+
update(name, args, fields) {
|
|
61
|
+
const context = this.createContext(name);
|
|
62
|
+
const fieldName = `update${name}`;
|
|
63
|
+
const typedArgs = createTypedArgs(args, {
|
|
64
|
+
data: `${context.entity.name}UpdateInput!`,
|
|
65
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
66
|
+
filter: `${context.entity.name}Where`
|
|
67
|
+
});
|
|
68
|
+
const selectionSet = this.createMutationSelection("update", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
69
|
+
return new ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
70
|
+
}
|
|
71
|
+
upsert(name, args, fields) {
|
|
72
|
+
const context = this.createContext(name);
|
|
73
|
+
const fieldName = `upsert${name}`;
|
|
74
|
+
const typedArgs = createTypedArgs(args, {
|
|
75
|
+
update: `${context.entity.name}UpdateInput!`,
|
|
76
|
+
create: `${context.entity.name}CreateInput!`,
|
|
77
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
78
|
+
filter: `${context.entity.name}Where`
|
|
79
|
+
});
|
|
80
|
+
const selectionSet = this.createMutationSelection("upsert", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
81
|
+
return new ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
82
|
+
}
|
|
83
|
+
delete(name, args, fields) {
|
|
84
|
+
const context = this.createContext(name);
|
|
85
|
+
const typedArgs = createTypedArgs(args, {
|
|
86
|
+
by: `${context.entity.name}UniqueWhere!`,
|
|
87
|
+
filter: `${context.entity.name}Where`
|
|
88
|
+
});
|
|
89
|
+
const fieldName = `delete${name}`;
|
|
90
|
+
const selectionSet = this.createMutationSelection("delete", fields ? this.resolveSelectionSet(fields, context) : void 0);
|
|
91
|
+
return new ContentOperation("mutation", fieldName, typedArgs, selectionSet);
|
|
92
|
+
}
|
|
93
|
+
transaction(input, options = {}) {
|
|
94
|
+
const combined = createMutationOperationSet(input);
|
|
95
|
+
const transactionArgs = createTypedArgs({ options }, {
|
|
96
|
+
options: "MutationTransactionOptions"
|
|
97
|
+
});
|
|
98
|
+
const items = [
|
|
99
|
+
...this.createMutationSelection("transaction"),
|
|
100
|
+
...combined.selection
|
|
101
|
+
];
|
|
102
|
+
return new ContentOperation("mutation", "transaction", transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {
|
|
103
|
+
return {
|
|
104
|
+
ok,
|
|
105
|
+
errorMessage,
|
|
106
|
+
errors,
|
|
107
|
+
validation,
|
|
108
|
+
data: combined.parse(data)
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
createMutationSelection(operation, selection) {
|
|
113
|
+
const items = [
|
|
114
|
+
new GraphQlField(null, "ok"),
|
|
115
|
+
new GraphQlField(null, "errorMessage"),
|
|
116
|
+
new GraphQlField(null, "errors", {}, [
|
|
117
|
+
new GraphQlFragmentSpread("MutationError")
|
|
118
|
+
])
|
|
119
|
+
];
|
|
120
|
+
if (operation !== "delete") {
|
|
121
|
+
items.push(new GraphQlField(null, "validation", {}, [
|
|
122
|
+
new GraphQlFragmentSpread("ValidationResult")
|
|
123
|
+
]));
|
|
124
|
+
}
|
|
125
|
+
if (selection) {
|
|
126
|
+
items.push(new GraphQlField(null, "node", {}, selection));
|
|
127
|
+
}
|
|
128
|
+
return items;
|
|
129
|
+
}
|
|
130
|
+
resolveSelectionSet(fields, context) {
|
|
131
|
+
return (typeof fields === "function" ? fields(new ContentEntitySelection(context, [])) : fields).selectionSet;
|
|
132
|
+
}
|
|
133
|
+
createContext(name) {
|
|
134
|
+
const entity = this.schema.entities[name];
|
|
135
|
+
if (!entity) {
|
|
136
|
+
throw new Error(`Entity ${name} not found`);
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
entity,
|
|
140
|
+
schema: this.schema
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export {
|
|
145
|
+
ContentQueryBuilder
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=ContentQueryBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentQueryBuilder.js","sources":["../../src/ContentQueryBuilder.ts"],"sourcesContent":["import { ContentClientInput, MutationResult, SchemaNames, TransactionResult } from './types'\nimport {\n\tContentEntitySelection,\n\tContentEntitySelectionCallback,\n\tContentEntitySelectionContext,\n\tContentMutation,\n\tContentOperation,\n\tContentQuery,\n} from './nodes'\nimport { createListArgs } from './utils/createListArgs'\nimport { createTypedArgs } from './utils/createTypedArgs'\nimport { Input } from '@contember/schema'\nimport { GraphQlField, GraphQlFragmentSpread, GraphQlSelectionSet } from '@contember/graphql-builder'\nimport { createMutationOperationSet } from './utils/createMutationOperationSet'\n\nexport type EntitySelectionOrCallback =\n\t| ContentEntitySelection\n\t| ContentEntitySelectionCallback\n\nexport type MutationTransactionOptions = {\n\tdeferForeignKeyConstraints?: boolean\n\tdeferUniqueConstraints?: boolean\n}\n\nexport class ContentQueryBuilder {\n\tconstructor(private readonly schema: SchemaNames) {\n\t}\n\n\n\tpublic fragment(name: string, fieldsCallback?: ContentEntitySelectionCallback): ContentEntitySelection {\n\t\tconst context = this.createContext(name)\n\n\t\tconst entitySelection = new ContentEntitySelection(context, [])\n\t\tif (!fieldsCallback) {\n\t\t\treturn entitySelection\n\t\t}\n\t\treturn fieldsCallback(entitySelection)\n\t}\n\n\n\n\tpublic count(name: string, args: Pick<ContentClientInput.AnyListQueryInput, 'filter'>): ContentQuery<number> {\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `paginate${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst selectionSet: GraphQlSelectionSet = [\n\t\t\tnew GraphQlField(null, 'pageInfo', {}, [\n\t\t\t\tnew GraphQlField(null, 'totalCount'),\n\t\t\t]),\n\t\t]\n\n\t\treturn new ContentOperation('query', fieldName, typedArgs, selectionSet, it => {\n\t\t\treturn it.pageInfo.totalCount\n\t\t})\n\t}\n\n\n\tpublic list(name: string, args: ContentClientInput.AnyListQueryInput, fields: EntitySelectionOrCallback): ContentQuery<any[]> {\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `list${name}`\n\t\tconst typedArgs = createListArgs(context.entity, args)\n\t\tconst selectionSet = this.resolveSelectionSet(fields, context)\n\n\t\treturn new ContentOperation('query', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic get(name: string, args: Input.UniqueQueryInput, fields: EntitySelectionOrCallback): ContentQuery<Record<string, unknown> | null> {\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `get${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst selectionSet = this.resolveSelectionSet(fields, context)\n\n\t\treturn new ContentOperation('query', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic create(name: string, args: Input.CreateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `create${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tdata: `${context.entity.name}CreateInput!`,\n\t\t})\n\t\tconst selectionSet = this.createMutationSelection('create', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic update(name: string, args: Input.UpdateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `update${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tdata: `${context.entity.name}UpdateInput!`,\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst selectionSet = this.createMutationSelection('update', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic upsert(name: string, args: Input.UpsertInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst fieldName = `upsert${name}`\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tupdate: `${context.entity.name}UpdateInput!`,\n\t\t\tcreate: `${context.entity.name}CreateInput!`,\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\n\t\tconst selectionSet = this.createMutationSelection('upsert', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\n\tpublic delete(name: string, args: Input.UniqueQueryInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {\n\n\t\tconst context = this.createContext(name)\n\t\tconst typedArgs = createTypedArgs(args, {\n\t\t\tby: `${context.entity.name}UniqueWhere!`,\n\t\t\tfilter: `${context.entity.name}Where`,\n\t\t})\n\t\tconst fieldName = `delete${name}`\n\t\tconst selectionSet = this.createMutationSelection('delete', fields ? this.resolveSelectionSet(fields, context) : undefined)\n\n\t\treturn new ContentOperation('mutation', fieldName, typedArgs, selectionSet)\n\t}\n\n\tpublic transaction(\n\t\tinput: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[],\n\t\toptions: MutationTransactionOptions = {},\n\t): ContentMutation<TransactionResult<any>> {\n\t\tconst combined = createMutationOperationSet(input)\n\n\t\tconst transactionArgs = createTypedArgs({ options }, {\n\t\t\toptions: 'MutationTransactionOptions',\n\t\t})\n\t\tconst items = [\n\t\t\t...this.createMutationSelection('transaction'),\n\t\t\t...combined.selection,\n\t\t]\n\t\treturn new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {\n\t\t\treturn {\n\t\t\t\tok,\n\t\t\t\terrorMessage,\n\t\t\t\terrors,\n\t\t\t\tvalidation,\n\t\t\t\tdata: combined.parse(data),\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate createMutationSelection(operation: 'create' | 'update' | 'delete' | 'upsert' | 'transaction', selection?: GraphQlSelectionSet): GraphQlSelectionSet {\n\t\tconst items: GraphQlSelectionSet = [\n\t\t\tnew GraphQlField(null, 'ok'),\n\t\t\tnew GraphQlField(null, 'errorMessage'),\n\t\t\tnew GraphQlField(null, 'errors', {}, [\n\t\t\t\tnew GraphQlFragmentSpread('MutationError'),\n\t\t\t]),\n\t\t]\n\t\tif (operation !== 'delete') {\n\t\t\titems.push(new GraphQlField(null, 'validation', {}, [\n\t\t\t\tnew GraphQlFragmentSpread('ValidationResult'),\n\t\t\t]))\n\t\t}\n\t\tif (selection) {\n\t\t\titems.push(new GraphQlField(null, 'node', {}, selection))\n\t\t}\n\t\treturn items\n\t}\n\n\n\tprivate resolveSelectionSet(\n\t\tfields: EntitySelectionOrCallback,\n\t\tcontext: ContentEntitySelectionContext<string>,\n\t) {\n\t\treturn (typeof fields === 'function' ? fields(new ContentEntitySelection(context, [])) : fields).selectionSet\n\t}\n\n\tprivate createContext(\n\t\tname: string,\n\t): ContentEntitySelectionContext<string> {\n\t\tconst entity = this.schema.entities[name]\n\t\tif (!entity) {\n\t\t\tthrow new Error(`Entity ${name} not found`)\n\t\t}\n\t\treturn {\n\t\t\tentity: entity,\n\t\t\tschema: this.schema,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAwBO,MAAM,oBAAoB;AAAA,EAChC,YAA6B,QAAqB;AAArB,SAAA,SAAA;AAAA,EAC7B;AAAA,EAGO,SAAS,MAAc,gBAAyE;AAChG,UAAA,UAAU,KAAK,cAAc,IAAI;AAEvC,UAAM,kBAAkB,IAAI,uBAAuB,SAAS,CAAE,CAAA;AAC9D,QAAI,CAAC,gBAAgB;AACb,aAAA;AAAA,IACR;AACA,WAAO,eAAe,eAAe;AAAA,EACtC;AAAA,EAIO,MAAM,MAAc,MAAkF;AACtG,UAAA,UAAU,KAAK,cAAc,IAAI;AACvC,UAAM,YAAY,WAAW;AACvB,UAAA,YAAY,gBAAgB,MAAM;AAAA,MACvC,QAAQ,GAAG,QAAQ,OAAO;AAAA,IAAA,CAC1B;AACD,UAAM,eAAoC;AAAA,MACzC,IAAI,aAAa,MAAM,YAAY,IAAI;AAAA,QACtC,IAAI,aAAa,MAAM,YAAY;AAAA,MAAA,CACnC;AAAA,IAAA;AAGF,WAAO,IAAI,iBAAiB,SAAS,WAAW,WAAW,cAAc,CAAM,OAAA;AAC9E,aAAO,GAAG,SAAS;AAAA,IAAA,CACnB;AAAA,EACF;AAAA,EAGO,KAAK,MAAc,MAA4C,QAAwD;AACvH,UAAA,UAAU,KAAK,cAAc,IAAI;AACvC,UAAM,YAAY,OAAO;AACzB,UAAM,YAAY,eAAe,QAAQ,QAAQ,IAAI;AACrD,UAAM,eAAe,KAAK,oBAAoB,QAAQ,OAAO;AAE7D,WAAO,IAAI,iBAAiB,SAAS,WAAW,WAAW,YAAY;AAAA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aAAa,MAAM,IAAI;AAAA,MAC3B,IAAI,aAAa,MAAM,cAAc;AAAA,MACrC,IAAI,aAAa,MAAM,UAAU,IAAI;AAAA,QACpC,IAAI,sBAAsB,eAAe;AAAA,MAAA,CACzC;AAAA,IAAA;AAEF,QAAI,cAAc,UAAU;AAC3B,YAAM,KAAK,IAAI,aAAa,MAAM,cAAc,CAAA,GAAI;AAAA,QACnD,IAAI,sBAAsB,kBAAkB;AAAA,MAC5C,CAAA,CAAC;AAAA,IACH;AACA,QAAI,WAAW;AACR,YAAA,KAAK,IAAI,aAAa,MAAM,QAAQ,CAAC,GAAG,SAAS,CAAC;AAAA,IACzD;AACO,WAAA;AAAA,EACR;AAAA,EAGQ,oBACP,QACA,SACC;AACO,YAAA,OAAO,WAAW,aAAa,OAAO,IAAI,uBAAuB,SAAS,CAAE,CAAA,CAAC,IAAI,QAAQ;AAAA,EAClG;AAAA,EAEQ,cACP,MACwC;AACxC,UAAM,SAAS,KAAK,OAAO,SAAS,IAAI;AACxC,QAAI,CAAC,QAAQ;AACN,YAAA,IAAI,MAAM,UAAU,gBAAgB;AAAA,IAC3C;AACO,WAAA;AAAA,MACN;AAAA,MACA,QAAQ,KAAK;AAAA,IAAA;AAAA,EAEf;AACD;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ContentClient = require("./ContentClient.cjs");
|
|
4
|
+
const ContentQueryBuilder = require("./ContentQueryBuilder.cjs");
|
|
5
|
+
const ContentEntitySelection = require("./nodes/ContentEntitySelection.cjs");
|
|
6
|
+
const ContentOperation = require("./nodes/ContentOperation.cjs");
|
|
7
|
+
exports.ContentClient = ContentClient.ContentClient;
|
|
8
|
+
exports.ContentQueryBuilder = ContentQueryBuilder.ContentQueryBuilder;
|
|
9
|
+
exports.ContentEntitySelection = ContentEntitySelection.ContentEntitySelection;
|
|
10
|
+
exports.ContentOperation = ContentOperation.ContentOperation;
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ContentClient } from "./ContentClient.js";
|
|
2
|
+
import { ContentQueryBuilder } from "./ContentQueryBuilder.js";
|
|
3
|
+
import { ContentEntitySelection } from "./nodes/ContentEntitySelection.js";
|
|
4
|
+
import { ContentOperation } from "./nodes/ContentOperation.js";
|
|
5
|
+
export {
|
|
6
|
+
ContentClient,
|
|
7
|
+
ContentEntitySelection,
|
|
8
|
+
ContentOperation,
|
|
9
|
+
ContentQueryBuilder
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createListArgs = require("../utils/createListArgs.cjs");
|
|
4
|
+
const graphqlBuilder = require("@contember/graphql-builder");
|
|
5
|
+
class ContentEntitySelection {
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
constructor(context, selectionSet) {
|
|
10
|
+
this.context = context;
|
|
11
|
+
this.selectionSet = selectionSet;
|
|
12
|
+
}
|
|
13
|
+
$(field, argsOrSelection, selectionIn) {
|
|
14
|
+
const [args, selection] = typeof argsOrSelection === "function" || argsOrSelection instanceof ContentEntitySelection ? [{}, argsOrSelection] : [argsOrSelection ?? {}, selectionIn];
|
|
15
|
+
if (field === "__typename") {
|
|
16
|
+
return this.withField(new graphqlBuilder.GraphQlField(args.as ?? null, "__typename"));
|
|
17
|
+
}
|
|
18
|
+
const fieldInfo = this.context.entity.fields[field];
|
|
19
|
+
if (!fieldInfo) {
|
|
20
|
+
if ("by" in args && field.includes("By")) {
|
|
21
|
+
if (!selection) {
|
|
22
|
+
throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
|
|
23
|
+
}
|
|
24
|
+
return this._manyBy(field, args, selection);
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Field ${this.context.entity.name}.${field} does not exist.`);
|
|
27
|
+
}
|
|
28
|
+
if (fieldInfo.type === "column") {
|
|
29
|
+
return this._column(field, args);
|
|
30
|
+
}
|
|
31
|
+
if (fieldInfo.type === "many") {
|
|
32
|
+
if (!selection) {
|
|
33
|
+
throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
|
|
34
|
+
}
|
|
35
|
+
return this._many(field, args, selection);
|
|
36
|
+
}
|
|
37
|
+
if (fieldInfo.type === "one") {
|
|
38
|
+
if (!selection) {
|
|
39
|
+
throw new Error(`Selection is required for ${this.context.entity.name}.${field}.`);
|
|
40
|
+
}
|
|
41
|
+
return this._one(field, args, selection);
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Unknown field type ${fieldInfo.type}.`);
|
|
44
|
+
}
|
|
45
|
+
$$() {
|
|
46
|
+
const columns = this.context.entity.scalars;
|
|
47
|
+
const nodes = [
|
|
48
|
+
...this.selectionSet,
|
|
49
|
+
...columns.map((col) => new graphqlBuilder.GraphQlField(null, col))
|
|
50
|
+
];
|
|
51
|
+
return new ContentEntitySelection(this.context, nodes);
|
|
52
|
+
}
|
|
53
|
+
_column(name, args = {}) {
|
|
54
|
+
let fieldInfo = this.context.entity.fields[name];
|
|
55
|
+
if (!fieldInfo) {
|
|
56
|
+
throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
|
|
57
|
+
}
|
|
58
|
+
if (fieldInfo?.type !== "column") {
|
|
59
|
+
throw new Error(`Field ${this.context.entity.name}.${name} is not a column.`);
|
|
60
|
+
}
|
|
61
|
+
const alias = args.as ?? name;
|
|
62
|
+
const field = new graphqlBuilder.GraphQlField(alias, name, {});
|
|
63
|
+
return this.withField(field);
|
|
64
|
+
}
|
|
65
|
+
_many(name, args, fields) {
|
|
66
|
+
const alias = args.as ?? name;
|
|
67
|
+
const fieldInfo = this.context.entity.fields[name];
|
|
68
|
+
if (!fieldInfo) {
|
|
69
|
+
throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
|
|
70
|
+
}
|
|
71
|
+
if (fieldInfo?.type !== "many") {
|
|
72
|
+
throw new Error(`Field ${this.context.entity.name}.${name} is not a has-many relation.`);
|
|
73
|
+
}
|
|
74
|
+
const entity = this.context.schema.entities[fieldInfo.entity];
|
|
75
|
+
const newContext = {
|
|
76
|
+
entity,
|
|
77
|
+
schema: this.context.schema
|
|
78
|
+
};
|
|
79
|
+
const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
|
|
80
|
+
const newObjectField = new graphqlBuilder.GraphQlField(
|
|
81
|
+
alias,
|
|
82
|
+
name,
|
|
83
|
+
createListArgs.createListArgs(entity, args),
|
|
84
|
+
entitySelection.selectionSet
|
|
85
|
+
);
|
|
86
|
+
return this.withField(newObjectField);
|
|
87
|
+
}
|
|
88
|
+
_manyBy(name, args, fields) {
|
|
89
|
+
const alias = args.as ?? name;
|
|
90
|
+
const byField = Object.keys(args.by)[0];
|
|
91
|
+
const relationField = name.substring(0, name.length - byField.length - 2);
|
|
92
|
+
const field = this.context.entity.fields[relationField];
|
|
93
|
+
if (!field) {
|
|
94
|
+
throw new Error(`Field ${this.context.entity.name}.${relationField} does not exist.`);
|
|
95
|
+
}
|
|
96
|
+
if (field?.type !== "many") {
|
|
97
|
+
throw new Error(`Field ${this.context.entity.name}.${relationField} is not a has-many relation.`);
|
|
98
|
+
}
|
|
99
|
+
const entity = this.context.schema.entities[field.entity];
|
|
100
|
+
const newContext = {
|
|
101
|
+
entity,
|
|
102
|
+
schema: this.context.schema
|
|
103
|
+
};
|
|
104
|
+
const fieldUpperFirst = name.charAt(0).toUpperCase() + name.slice(1);
|
|
105
|
+
const argsWithType = {
|
|
106
|
+
filter: {
|
|
107
|
+
graphQlType: `${entity.name}Where`,
|
|
108
|
+
value: args.filter
|
|
109
|
+
},
|
|
110
|
+
by: {
|
|
111
|
+
graphQlType: `${this.context.entity.name}${fieldUpperFirst}UniqueWhere!`,
|
|
112
|
+
value: args.by
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
|
|
116
|
+
const newObjectField = new graphqlBuilder.GraphQlField(
|
|
117
|
+
alias,
|
|
118
|
+
name,
|
|
119
|
+
argsWithType,
|
|
120
|
+
entitySelection.selectionSet
|
|
121
|
+
);
|
|
122
|
+
return this.withField(newObjectField);
|
|
123
|
+
}
|
|
124
|
+
_one(name, args, fields) {
|
|
125
|
+
const alias = args.as ?? name;
|
|
126
|
+
const fieldInfo = this.context.entity.fields[name];
|
|
127
|
+
if (!fieldInfo) {
|
|
128
|
+
throw new Error(`Field ${this.context.entity.name}.${name} does not exist.`);
|
|
129
|
+
}
|
|
130
|
+
if (fieldInfo?.type !== "one") {
|
|
131
|
+
throw new Error(`Field ${this.context.entity.name}.${name} is not a has-one relation.`);
|
|
132
|
+
}
|
|
133
|
+
const entity = this.context.schema.entities[fieldInfo.entity];
|
|
134
|
+
const newContext = {
|
|
135
|
+
entity,
|
|
136
|
+
schema: this.context.schema
|
|
137
|
+
};
|
|
138
|
+
const argsWithType = {
|
|
139
|
+
filter: {
|
|
140
|
+
graphQlType: `${entity.name}Where`,
|
|
141
|
+
value: args.filter
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const entitySelection = typeof fields === "function" ? fields(new ContentEntitySelection(newContext, [])) : fields;
|
|
145
|
+
const newObjectField = new graphqlBuilder.GraphQlField(
|
|
146
|
+
alias,
|
|
147
|
+
name,
|
|
148
|
+
argsWithType,
|
|
149
|
+
entitySelection.selectionSet
|
|
150
|
+
);
|
|
151
|
+
return this.withField(newObjectField);
|
|
152
|
+
}
|
|
153
|
+
withField(field) {
|
|
154
|
+
return new ContentEntitySelection(this.context, [
|
|
155
|
+
...this.selectionSet,
|
|
156
|
+
field
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.ContentEntitySelection = ContentEntitySelection;
|
|
161
|
+
//# sourceMappingURL=ContentEntitySelection.cjs.map
|