@contember/engine-content-api 2.2.0-alpha.19 → 2.2.0-alpha.20
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/CLAUDE.md +12 -7
- package/dist/development/index.cjs +23 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +25 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/ExecutionContainer.cjs +4 -3
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +4 -3
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- package/dist/development/src/acl/Authorizator.cjs +6 -1
- package/dist/development/src/acl/Authorizator.cjs.map +1 -1
- package/dist/development/src/acl/Authorizator.js +6 -1
- package/dist/development/src/acl/Authorizator.js.map +1 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -1
- package/dist/development/src/introspection/introspection.schema.cjs +2 -2
- package/dist/development/src/introspection/introspection.schema.cjs.map +1 -1
- package/dist/development/src/introspection/introspection.schema.js +2 -2
- package/dist/development/src/introspection/introspection.schema.js.map +1 -1
- package/dist/development/src/mapper/select/SelectHydrator.cjs +56 -15
- package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
- package/dist/development/src/mapper/select/SelectHydrator.js +56 -15
- package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
- package/dist/development/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
- package/dist/development/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.cjs +17 -39
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +18 -40
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/development/src/resolvers/ReadHelpers.cjs +4 -5
- package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
- package/dist/development/src/resolvers/ReadHelpers.js +4 -5
- package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
- package/dist/development/src/resolvers/ReadResolver.cjs +8 -17
- package/dist/development/src/resolvers/ReadResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/ReadResolver.js +8 -17
- package/dist/development/src/resolvers/ReadResolver.js.map +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilder.cjs +16 -6
- package/dist/development/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilder.js +16 -6
- package/dist/development/src/schema/GraphQlSchemaBuilder.js.map +1 -1
- package/dist/development/src/schema/MutationProvider.cjs +21 -8
- package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
- package/dist/development/src/schema/MutationProvider.js +21 -8
- package/dist/development/src/schema/MutationProvider.js.map +1 -1
- package/dist/development/src/schema/QueryProvider.cjs +6 -6
- package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
- package/dist/development/src/schema/QueryProvider.js +6 -6
- package/dist/development/src/schema/QueryProvider.js.map +1 -1
- package/dist/development/src/schema-json/GraphQLJsBridge.cjs +108 -0
- package/dist/development/src/schema-json/GraphQLJsBridge.cjs.map +1 -0
- package/dist/development/src/schema-json/GraphQLJsBridge.js +108 -0
- package/dist/development/src/schema-json/GraphQLJsBridge.js.map +1 -0
- package/dist/development/src/schema-json/JsonColumnTypes.cjs +102 -0
- package/dist/development/src/schema-json/JsonColumnTypes.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonColumnTypes.js +102 -0
- package/dist/development/src/schema-json/JsonColumnTypes.js.map +1 -0
- package/dist/development/src/schema-json/JsonContentSchemaBuilder.cjs +418 -0
- package/dist/development/src/schema-json/JsonContentSchemaBuilder.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonContentSchemaBuilder.js +418 -0
- package/dist/development/src/schema-json/JsonContentSchemaBuilder.js.map +1 -0
- package/dist/development/src/schema-json/JsonContentSchemaShared.cjs +18 -0
- package/dist/development/src/schema-json/JsonContentSchemaShared.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonContentSchemaShared.js +18 -0
- package/dist/development/src/schema-json/JsonContentSchemaShared.js.map +1 -0
- package/dist/development/src/schema-json/JsonEntityTypes.cjs +206 -0
- package/dist/development/src/schema-json/JsonEntityTypes.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonEntityTypes.js +206 -0
- package/dist/development/src/schema-json/JsonEntityTypes.js.map +1 -0
- package/dist/development/src/schema-json/JsonFilterTypes.cjs +152 -0
- package/dist/development/src/schema-json/JsonFilterTypes.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonFilterTypes.js +152 -0
- package/dist/development/src/schema-json/JsonFilterTypes.js.map +1 -0
- package/dist/development/src/schema-json/JsonInputTypes.cjs +256 -0
- package/dist/development/src/schema-json/JsonInputTypes.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonInputTypes.js +256 -0
- package/dist/development/src/schema-json/JsonInputTypes.js.map +1 -0
- package/dist/development/src/schema-json/JsonIntrospectionExtension.cjs +36 -0
- package/dist/development/src/schema-json/JsonIntrospectionExtension.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonIntrospectionExtension.js +36 -0
- package/dist/development/src/schema-json/JsonIntrospectionExtension.js.map +1 -0
- package/dist/development/src/schema-json/JsonQueryAstFactory.cjs +107 -0
- package/dist/development/src/schema-json/JsonQueryAstFactory.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonQueryAstFactory.js +107 -0
- package/dist/development/src/schema-json/JsonQueryAstFactory.js.map +1 -0
- package/dist/development/src/schema-json/JsonTypeRegistry.cjs +230 -0
- package/dist/development/src/schema-json/JsonTypeRegistry.cjs.map +1 -0
- package/dist/development/src/schema-json/JsonTypeRegistry.js +230 -0
- package/dist/development/src/schema-json/JsonTypeRegistry.js.map +1 -0
- package/dist/development/src/utils/ResolveInfoUtils.cjs.map +1 -1
- package/dist/development/src/utils/ResolveInfoUtils.js.map +1 -1
- package/dist/development/src/utils/uniqueWhereFields.cjs +10 -0
- package/dist/development/src/utils/uniqueWhereFields.cjs.map +1 -1
- package/dist/development/src/utils/uniqueWhereFields.js +10 -0
- package/dist/development/src/utils/uniqueWhereFields.js.map +1 -1
- package/dist/production/index.cjs +23 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +25 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/ExecutionContainer.cjs +4 -3
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +4 -3
- package/dist/production/src/ExecutionContainer.js.map +1 -1
- package/dist/production/src/acl/Authorizator.cjs +6 -1
- package/dist/production/src/acl/Authorizator.cjs.map +1 -1
- package/dist/production/src/acl/Authorizator.js +6 -1
- package/dist/production/src/acl/Authorizator.js.map +1 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -1
- package/dist/production/src/introspection/introspection.schema.cjs +2 -2
- package/dist/production/src/introspection/introspection.schema.cjs.map +1 -1
- package/dist/production/src/introspection/introspection.schema.js +2 -2
- package/dist/production/src/introspection/introspection.schema.js.map +1 -1
- package/dist/production/src/mapper/select/SelectHydrator.cjs +56 -15
- package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
- package/dist/production/src/mapper/select/SelectHydrator.js +56 -15
- package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
- package/dist/production/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
- package/dist/production/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.cjs +17 -39
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +18 -40
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/resolvers/ReadHelpers.cjs +4 -5
- package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
- package/dist/production/src/resolvers/ReadHelpers.js +4 -5
- package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
- package/dist/production/src/resolvers/ReadResolver.cjs +8 -17
- package/dist/production/src/resolvers/ReadResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/ReadResolver.js +8 -17
- package/dist/production/src/resolvers/ReadResolver.js.map +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilder.cjs +16 -6
- package/dist/production/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilder.js +16 -6
- package/dist/production/src/schema/GraphQlSchemaBuilder.js.map +1 -1
- package/dist/production/src/schema/MutationProvider.cjs +21 -8
- package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
- package/dist/production/src/schema/MutationProvider.js +21 -8
- package/dist/production/src/schema/MutationProvider.js.map +1 -1
- package/dist/production/src/schema/QueryProvider.cjs +6 -6
- package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
- package/dist/production/src/schema/QueryProvider.js +6 -6
- package/dist/production/src/schema/QueryProvider.js.map +1 -1
- package/dist/production/src/schema-json/GraphQLJsBridge.cjs +108 -0
- package/dist/production/src/schema-json/GraphQLJsBridge.cjs.map +1 -0
- package/dist/production/src/schema-json/GraphQLJsBridge.js +108 -0
- package/dist/production/src/schema-json/GraphQLJsBridge.js.map +1 -0
- package/dist/production/src/schema-json/JsonColumnTypes.cjs +102 -0
- package/dist/production/src/schema-json/JsonColumnTypes.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonColumnTypes.js +102 -0
- package/dist/production/src/schema-json/JsonColumnTypes.js.map +1 -0
- package/dist/production/src/schema-json/JsonContentSchemaBuilder.cjs +418 -0
- package/dist/production/src/schema-json/JsonContentSchemaBuilder.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonContentSchemaBuilder.js +418 -0
- package/dist/production/src/schema-json/JsonContentSchemaBuilder.js.map +1 -0
- package/dist/production/src/schema-json/JsonContentSchemaShared.cjs +18 -0
- package/dist/production/src/schema-json/JsonContentSchemaShared.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonContentSchemaShared.js +18 -0
- package/dist/production/src/schema-json/JsonContentSchemaShared.js.map +1 -0
- package/dist/production/src/schema-json/JsonEntityTypes.cjs +206 -0
- package/dist/production/src/schema-json/JsonEntityTypes.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonEntityTypes.js +206 -0
- package/dist/production/src/schema-json/JsonEntityTypes.js.map +1 -0
- package/dist/production/src/schema-json/JsonFilterTypes.cjs +152 -0
- package/dist/production/src/schema-json/JsonFilterTypes.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonFilterTypes.js +152 -0
- package/dist/production/src/schema-json/JsonFilterTypes.js.map +1 -0
- package/dist/production/src/schema-json/JsonInputTypes.cjs +256 -0
- package/dist/production/src/schema-json/JsonInputTypes.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonInputTypes.js +256 -0
- package/dist/production/src/schema-json/JsonInputTypes.js.map +1 -0
- package/dist/production/src/schema-json/JsonIntrospectionExtension.cjs +36 -0
- package/dist/production/src/schema-json/JsonIntrospectionExtension.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonIntrospectionExtension.js +36 -0
- package/dist/production/src/schema-json/JsonIntrospectionExtension.js.map +1 -0
- package/dist/production/src/schema-json/JsonQueryAstFactory.cjs +107 -0
- package/dist/production/src/schema-json/JsonQueryAstFactory.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonQueryAstFactory.js +107 -0
- package/dist/production/src/schema-json/JsonQueryAstFactory.js.map +1 -0
- package/dist/production/src/schema-json/JsonTypeRegistry.cjs +230 -0
- package/dist/production/src/schema-json/JsonTypeRegistry.cjs.map +1 -0
- package/dist/production/src/schema-json/JsonTypeRegistry.js +230 -0
- package/dist/production/src/schema-json/JsonTypeRegistry.js.map +1 -0
- package/dist/production/src/utils/ResolveInfoUtils.cjs.map +1 -1
- package/dist/production/src/utils/ResolveInfoUtils.js.map +1 -1
- package/dist/production/src/utils/uniqueWhereFields.cjs +10 -0
- package/dist/production/src/utils/uniqueWhereFields.cjs.map +1 -1
- package/dist/production/src/utils/uniqueWhereFields.js +10 -0
- package/dist/production/src/utils/uniqueWhereFields.js.map +1 -1
- package/dist/tests/src/test.d.ts +10 -2
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/src/testGraphql.d.ts +18 -5
- package/dist/tests/src/testGraphql.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ExecutionContainer.d.ts +1 -0
- package/dist/types/ExecutionContainer.d.ts.map +1 -1
- package/dist/types/acl/Authorizator.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectHydrator.d.ts +4 -1
- package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
- package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts +4 -3
- package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
- package/dist/types/resolvers/MutationResolver.d.ts +14 -11
- package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
- package/dist/types/resolvers/ReadHelpers.d.ts +1 -2
- package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
- package/dist/types/resolvers/ReadResolver.d.ts +8 -10
- package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
- package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
- package/dist/types/schema/MutationProvider.d.ts.map +1 -1
- package/dist/types/schema-json/GraphQLJsBridge.d.ts +12 -0
- package/dist/types/schema-json/GraphQLJsBridge.d.ts.map +1 -0
- package/dist/types/schema-json/JsonColumnTypes.d.ts +23 -0
- package/dist/types/schema-json/JsonColumnTypes.d.ts.map +1 -0
- package/dist/types/schema-json/JsonContentSchemaBuilder.d.ts +56 -0
- package/dist/types/schema-json/JsonContentSchemaBuilder.d.ts.map +1 -0
- package/dist/types/schema-json/JsonContentSchemaShared.d.ts +19 -0
- package/dist/types/schema-json/JsonContentSchemaShared.d.ts.map +1 -0
- package/dist/types/schema-json/JsonEntityTypes.d.ts +29 -0
- package/dist/types/schema-json/JsonEntityTypes.d.ts.map +1 -0
- package/dist/types/schema-json/JsonFilterTypes.d.ts +21 -0
- package/dist/types/schema-json/JsonFilterTypes.d.ts.map +1 -0
- package/dist/types/schema-json/JsonInputTypes.d.ts +36 -0
- package/dist/types/schema-json/JsonInputTypes.d.ts.map +1 -0
- package/dist/types/schema-json/JsonIntrospectionExtension.d.ts +5 -0
- package/dist/types/schema-json/JsonIntrospectionExtension.d.ts.map +1 -0
- package/dist/types/schema-json/JsonQueryAstFactory.d.ts +18 -0
- package/dist/types/schema-json/JsonQueryAstFactory.d.ts.map +1 -0
- package/dist/types/schema-json/JsonTypeRegistry.d.ts +57 -0
- package/dist/types/schema-json/JsonTypeRegistry.d.ts.map +1 -0
- package/dist/types/schema-json/index.d.ts +7 -0
- package/dist/types/schema-json/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/ResolveInfoUtils.d.ts +4 -2
- package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
- package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/ExecutionContainer.ts +5 -3
- package/src/acl/Authorizator.ts +7 -1
- package/src/index.ts +1 -0
- package/src/mapper/select/SelectHydrator.ts +72 -17
- package/src/resolvers/GraphQlQueryAstFactory.ts +2 -2
- package/src/resolvers/MutationResolver.ts +22 -45
- package/src/resolvers/ReadHelpers.ts +1 -4
- package/src/resolvers/ReadResolver.ts +7 -18
- package/src/schema/GraphQlSchemaBuilder.ts +18 -7
- package/src/schema/MutationProvider.ts +21 -8
- package/src/schema/QueryProvider.ts +6 -6
- package/src/schema-json/GraphQLJsBridge.ts +142 -0
- package/src/schema-json/JsonColumnTypes.ts +116 -0
- package/src/schema-json/JsonContentSchemaBuilder.ts +501 -0
- package/src/schema-json/JsonContentSchemaShared.ts +19 -0
- package/src/schema-json/JsonEntityTypes.ts +237 -0
- package/src/schema-json/JsonFilterTypes.ts +159 -0
- package/src/schema-json/JsonInputTypes.ts +305 -0
- package/src/schema-json/JsonIntrospectionExtension.ts +37 -0
- package/src/schema-json/JsonQueryAstFactory.ts +128 -0
- package/src/schema-json/JsonTypeRegistry.ts +286 -0
- package/src/schema-json/index.ts +6 -0
- package/src/tsconfig.json +1 -0
- package/src/utils/ResolveInfoUtils.ts +2 -2
- package/src/utils/uniqueWhereFields.ts +14 -0
- package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +2 -3
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +44 -1
- package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +25 -29
- package/tests/src/test.ts +44 -10
- package/tests/src/testGraphql.ts +43 -20
- package/tests/tsconfig.json +1 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Argument,
|
|
3
|
+
EnumValue,
|
|
4
|
+
Field,
|
|
5
|
+
InputField,
|
|
6
|
+
isSpecifiedScalarTypeName,
|
|
7
|
+
ResolverFn,
|
|
8
|
+
ResolverMap,
|
|
9
|
+
ScalarImplementation,
|
|
10
|
+
specifiedScalarTypes,
|
|
11
|
+
Type,
|
|
12
|
+
TypeKind,
|
|
13
|
+
TypeRef,
|
|
14
|
+
} from '@contember/graphql-json'
|
|
15
|
+
import { Context } from '../types.js'
|
|
16
|
+
|
|
17
|
+
export type FieldExtensions = Record<string, unknown>
|
|
18
|
+
|
|
19
|
+
export interface JsonOutputField {
|
|
20
|
+
type: TypeRef
|
|
21
|
+
args?: Record<string, Argument>
|
|
22
|
+
resolve?: ResolverFn<unknown, Context>
|
|
23
|
+
extensions?: FieldExtensions
|
|
24
|
+
description?: string
|
|
25
|
+
deprecationReason?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Collects the JSON types of one content schema. Types are referenced by name, so a type is registered before its
|
|
30
|
+
* fields are created - a recursive reference (e.g. `Where.and`) then only resolves the name.
|
|
31
|
+
* Fields are created later, by `fillPending`: one type at a time, so that a build can pause between them instead of
|
|
32
|
+
* running the whole graph a single entity reaches in one go.
|
|
33
|
+
* Resolvers, field extensions and scalars go to maps shared by all schemas of the model; the first registration wins.
|
|
34
|
+
*/
|
|
35
|
+
export class JsonTypeRegistry {
|
|
36
|
+
public readonly types: Record<string, Type> = {}
|
|
37
|
+
private readonly pending: (() => void)[] = []
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
public readonly resolvers: ResolverMap<Context>,
|
|
41
|
+
public readonly extensions: Record<string, Record<string, FieldExtensions>>,
|
|
42
|
+
public readonly scalars: Record<string, ScalarImplementation>,
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
public has(name: string): boolean {
|
|
46
|
+
return name in this.types
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public object(
|
|
50
|
+
name: string,
|
|
51
|
+
createFields: () => Record<string, JsonOutputField>,
|
|
52
|
+
interfaces: string[] = [],
|
|
53
|
+
description?: string,
|
|
54
|
+
): string {
|
|
55
|
+
if (this.types[name]) {
|
|
56
|
+
return name
|
|
57
|
+
}
|
|
58
|
+
const fields: Record<string, Field> = {}
|
|
59
|
+
this.types[name] = description !== undefined ? [TypeKind.OBJECT, fields, interfaces, description] : [TypeKind.OBJECT, fields, interfaces]
|
|
60
|
+
for (const interfaceName of interfaces) {
|
|
61
|
+
this.addPossibleType(interfaceName, name)
|
|
62
|
+
}
|
|
63
|
+
this.pending.push(() => this.addOutputFields(name, fields, createFields()))
|
|
64
|
+
return name
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public interface(name: string, createFields: () => Record<string, JsonOutputField>): string {
|
|
68
|
+
if (this.types[name]) {
|
|
69
|
+
return name
|
|
70
|
+
}
|
|
71
|
+
const fields: Record<string, Field> = {}
|
|
72
|
+
this.types[name] = [TypeKind.INTERFACE, fields, [], []]
|
|
73
|
+
this.pending.push(() => this.addOutputFields(name, fields, createFields()))
|
|
74
|
+
return name
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public union(name: string, possibleTypes: string[]): string {
|
|
78
|
+
if (!this.types[name]) {
|
|
79
|
+
this.types[name] = [TypeKind.UNION, possibleTypes]
|
|
80
|
+
}
|
|
81
|
+
return name
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public inputObject(name: string, createFields: () => Record<string, InputField>): string {
|
|
85
|
+
if (this.types[name]) {
|
|
86
|
+
return name
|
|
87
|
+
}
|
|
88
|
+
const fields: Record<string, InputField> = {}
|
|
89
|
+
this.types[name] = [TypeKind.INPUT_OBJECT, fields]
|
|
90
|
+
this.pending.push(() => Object.assign(fields, createFields()))
|
|
91
|
+
return name
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public enum(name: string, values: readonly string[]): string {
|
|
95
|
+
if (!this.types[name]) {
|
|
96
|
+
const enumValues: Record<string, EnumValue> = {}
|
|
97
|
+
for (const value of values) {
|
|
98
|
+
enumValues[value] = [value]
|
|
99
|
+
}
|
|
100
|
+
this.types[name] = [TypeKind.ENUM, enumValues]
|
|
101
|
+
}
|
|
102
|
+
return name
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public scalar(name: string, implementation: ScalarImplementation | undefined, description?: string): string {
|
|
106
|
+
if (!this.types[name]) {
|
|
107
|
+
this.types[name] = isSpecifiedScalarTypeName(name)
|
|
108
|
+
? specifiedScalarTypes[name]
|
|
109
|
+
: description !== undefined
|
|
110
|
+
? [TypeKind.SCALAR, description]
|
|
111
|
+
: [TypeKind.SCALAR]
|
|
112
|
+
}
|
|
113
|
+
if (implementation) {
|
|
114
|
+
this.scalars[name] ??= implementation
|
|
115
|
+
}
|
|
116
|
+
return name
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Creates the fields of the registered types, including the types that creates; yields after each type. */
|
|
120
|
+
public *fillPending(): Generator<void, void> {
|
|
121
|
+
// the queue grows while it is processed
|
|
122
|
+
for (let i = 0; i < this.pending.length; i++) {
|
|
123
|
+
this.pending[i]()
|
|
124
|
+
yield
|
|
125
|
+
}
|
|
126
|
+
this.pending.length = 0
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The types the schema consists of, collected the way graphql-js collects them (`GraphQLSchema` constructor):
|
|
131
|
+
* `includedTypes` first, then everything `roots` reach, depth-first. The order is what introspection and the
|
|
132
|
+
* printed schema list, so it stays the order graphql-js produced. Providers create some types speculatively
|
|
133
|
+
* (e.g. an input that the allowed operations then filter out); unreachable ones are left out.
|
|
134
|
+
* Returns a new record: deleting from a large object would turn it into a slow dictionary.
|
|
135
|
+
* Yields after each collected type.
|
|
136
|
+
*/
|
|
137
|
+
public *collectReachableTypes(
|
|
138
|
+
includedTypes: readonly string[],
|
|
139
|
+
roots: readonly string[],
|
|
140
|
+
otherTypes: Record<string, Type>,
|
|
141
|
+
): Generator<void, Record<string, Type>> {
|
|
142
|
+
const reachable = new Set<string>(includedTypes)
|
|
143
|
+
const getType = (name: string): Type | undefined => this.types[name] ?? otherTypes[name]
|
|
144
|
+
// an explicit stack instead of recursion keeps the pre-order of a recursive walk and can pause after any type
|
|
145
|
+
const collect = function*(name: string): Generator<void, void> {
|
|
146
|
+
const names: (readonly string[])[] = [[name]]
|
|
147
|
+
const positions: number[] = [0]
|
|
148
|
+
while (names.length > 0) {
|
|
149
|
+
const top = names.length - 1
|
|
150
|
+
const next = names[top][positions[top]++]
|
|
151
|
+
if (next === undefined) {
|
|
152
|
+
names.pop()
|
|
153
|
+
positions.pop()
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
const type = reachable.has(next) ? undefined : getType(next)
|
|
157
|
+
if (!type) {
|
|
158
|
+
continue
|
|
159
|
+
}
|
|
160
|
+
reachable.add(next)
|
|
161
|
+
names.push(getReferencedTypes(type))
|
|
162
|
+
positions.push(0)
|
|
163
|
+
yield
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// graphql-js seeds the set with the included types and re-adds each one, which moves it to the end
|
|
167
|
+
for (const name of includedTypes) {
|
|
168
|
+
reachable.delete(name)
|
|
169
|
+
yield* collect(name)
|
|
170
|
+
}
|
|
171
|
+
for (const root of roots) {
|
|
172
|
+
yield* collect(root)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const types: Record<string, Type> = {}
|
|
176
|
+
for (const name of reachable) {
|
|
177
|
+
const type = getType(name)
|
|
178
|
+
if (!type) {
|
|
179
|
+
continue
|
|
180
|
+
}
|
|
181
|
+
// replaced, not mutated: extension types are shared between schemas
|
|
182
|
+
if (type[0] === TypeKind.INTERFACE && type[3].some(it => !reachable.has(it))) {
|
|
183
|
+
const possibleTypes = type[3].filter(it => reachable.has(it))
|
|
184
|
+
types[name] = type[4] !== undefined
|
|
185
|
+
? [TypeKind.INTERFACE, type[1], type[2], possibleTypes, type[4]]
|
|
186
|
+
: [TypeKind.INTERFACE, type[1], type[2], possibleTypes]
|
|
187
|
+
} else {
|
|
188
|
+
types[name] = type
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return types
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private addPossibleType(interfaceName: string, typeName: string): void {
|
|
195
|
+
const interfaceType = this.types[interfaceName]
|
|
196
|
+
if (!interfaceType || interfaceType[0] !== TypeKind.INTERFACE) {
|
|
197
|
+
throw new Error(`Interface ${interfaceName} must be registered before ${typeName}`)
|
|
198
|
+
}
|
|
199
|
+
interfaceType[3].push(typeName)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private addOutputFields(typeName: string, target: Record<string, Field>, fields: Record<string, JsonOutputField>): void {
|
|
203
|
+
for (const [fieldName, field] of Object.entries(fields)) {
|
|
204
|
+
target[fieldName] = field.deprecationReason !== undefined
|
|
205
|
+
? [field.type, field.args ?? null, field.description, field.deprecationReason]
|
|
206
|
+
: field.description !== undefined
|
|
207
|
+
? [field.type, field.args ?? null, field.description]
|
|
208
|
+
: [field.type, field.args ?? null]
|
|
209
|
+
if (field.resolve) {
|
|
210
|
+
;(this.resolvers[typeName] ??= {})[fieldName] ??= field.resolve
|
|
211
|
+
}
|
|
212
|
+
if (field.extensions) {
|
|
213
|
+
;(this.extensions[typeName] ??= {})[fieldName] ??= field.extensions
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The names a type refers to, in the order graphql-js visits them: interfaces, then each field's type and arguments. */
|
|
220
|
+
const getReferencedTypes = (type: Type): string[] => {
|
|
221
|
+
const names: string[] = []
|
|
222
|
+
switch (type[0]) {
|
|
223
|
+
case TypeKind.OBJECT:
|
|
224
|
+
case TypeKind.INTERFACE:
|
|
225
|
+
names.push(...type[2])
|
|
226
|
+
for (const fieldName in type[1]) {
|
|
227
|
+
const field = type[1][fieldName]
|
|
228
|
+
if (!field) {
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
names.push(field[0][1])
|
|
232
|
+
for (const argName in field[1]) {
|
|
233
|
+
const arg = field[1][argName]
|
|
234
|
+
if (arg) {
|
|
235
|
+
names.push(arg[0][1])
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
break
|
|
240
|
+
case TypeKind.UNION:
|
|
241
|
+
names.push(...type[1])
|
|
242
|
+
break
|
|
243
|
+
case TypeKind.INPUT_OBJECT:
|
|
244
|
+
for (const fieldName in type[1]) {
|
|
245
|
+
const field = type[1][fieldName]
|
|
246
|
+
if (field) {
|
|
247
|
+
names.push(field[0][1])
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
break
|
|
251
|
+
}
|
|
252
|
+
return names
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** An input field without a default value; the description is left out of the tuple when there is none. */
|
|
256
|
+
export const inputField = (type: TypeRef, description: string | undefined): InputField =>
|
|
257
|
+
description !== undefined ? [type, undefined, description] : [type]
|
|
258
|
+
|
|
259
|
+
/** Wrap patterns of graphql-json `TypeRef`, named after the SDL they produce. */
|
|
260
|
+
const TypeRefPattern = {
|
|
261
|
+
named: 0, // T
|
|
262
|
+
nonNull: 1, // T!
|
|
263
|
+
list: 2, // [T]
|
|
264
|
+
listOfNonNull: 3, // [T!]
|
|
265
|
+
nonNullListOfNonNull: 5, // [T!]!
|
|
266
|
+
nonNullListOfNonNullListOfNonNull: 13, // [[T!]!]!
|
|
267
|
+
} as const
|
|
268
|
+
|
|
269
|
+
export const namedRef = (name: string): TypeRef => [TypeRefPattern.named, name]
|
|
270
|
+
export const nonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNull, name]
|
|
271
|
+
export const listRef = (name: string): TypeRef => [TypeRefPattern.list, name]
|
|
272
|
+
export const listOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.listOfNonNull, name]
|
|
273
|
+
export const nonNullListOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNullListOfNonNull, name]
|
|
274
|
+
export const nonNullListOfNonNullListOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNullListOfNonNullListOfNonNull, name]
|
|
275
|
+
|
|
276
|
+
/** `T` → `T!`, `[T!]` → `[T!]!` */
|
|
277
|
+
export const toNonNull = (ref: TypeRef): TypeRef => {
|
|
278
|
+
switch (ref[0]) {
|
|
279
|
+
case TypeRefPattern.named:
|
|
280
|
+
return [TypeRefPattern.nonNull, ref[1]]
|
|
281
|
+
case TypeRefPattern.listOfNonNull:
|
|
282
|
+
return [TypeRefPattern.nonNullListOfNonNull, ref[1]]
|
|
283
|
+
default:
|
|
284
|
+
throw new Error(`Cannot wrap type ref pattern ${ref[0]} in non-null`)
|
|
285
|
+
}
|
|
286
|
+
}
|
package/src/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FieldNode as GraphQlFieldNode,
|
|
1
|
+
import { FieldNode as GraphQlFieldNode, SelectionSetNode } from 'graphql'
|
|
2
2
|
|
|
3
3
|
export class ResolveInfoUtils {
|
|
4
|
-
public static extractFieldNode(info:
|
|
4
|
+
public static extractFieldNode(info: { readonly fieldNodes: readonly GraphQlFieldNode[] }): GraphQlFieldNode {
|
|
5
5
|
const newGraphQlFieldNodes = [...info.fieldNodes]
|
|
6
6
|
while (newGraphQlFieldNodes.length > 1) {
|
|
7
7
|
newGraphQlFieldNodes.push(
|
|
@@ -2,7 +2,21 @@ import { acceptEveryFieldVisitor } from '@contember/schema-utils'
|
|
|
2
2
|
import { Model } from '@contember/schema'
|
|
3
3
|
|
|
4
4
|
type SingleUnique = readonly string[]
|
|
5
|
+
|
|
6
|
+
// depends on the entity alone; schema builds ask for it per relation and role, requests per unique where
|
|
7
|
+
const uniqueWhereFields = new WeakMap<Model.Entity, readonly SingleUnique[]>()
|
|
8
|
+
|
|
5
9
|
export const getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {
|
|
10
|
+
const cached = uniqueWhereFields.get(entity)
|
|
11
|
+
if (cached) {
|
|
12
|
+
return cached
|
|
13
|
+
}
|
|
14
|
+
const fields = createFieldsForUniqueWhere(schema, entity)
|
|
15
|
+
uniqueWhereFields.set(entity, fields)
|
|
16
|
+
return fields
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const createFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {
|
|
6
20
|
const relations = Object.values(
|
|
7
21
|
acceptEveryFieldVisitor<undefined | [string]>(schema, entity, {
|
|
8
22
|
visitColumn: () => undefined,
|
|
@@ -2,7 +2,6 @@ import { test } from 'bun:test'
|
|
|
2
2
|
import { execute, failedTransaction, sqlTransaction } from '../../../../src/test.js'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
4
|
import { Model } from '@contember/schema'
|
|
5
|
-
import { RequestMemoryBudget } from '@contember/database'
|
|
6
5
|
import { GQL, SQL } from '../../../../src/tags.js'
|
|
7
6
|
import { testUuid } from '../../../../src/testUuid.js'
|
|
8
7
|
|
|
@@ -35,7 +34,7 @@ test('an exhausted memory budget fails every field of a mutation transaction', a
|
|
|
35
34
|
schema: new SchemaBuilder()
|
|
36
35
|
.entity('Author', entity => entity.column('name', c => c.type(Model.ColumnType.String)))
|
|
37
36
|
.buildSchema(),
|
|
38
|
-
memoryBudget:
|
|
37
|
+
memoryBudget: { warnBytes: 200, maxBytes: 200 },
|
|
39
38
|
query: GQL`
|
|
40
39
|
mutation {
|
|
41
40
|
transaction {
|
|
@@ -74,7 +73,7 @@ test('an exhausted memory budget fails its own mutation and keeps the committed
|
|
|
74
73
|
.entity('Author', entity => entity.column('name', c => c.type(Model.ColumnType.String)))
|
|
75
74
|
.buildSchema(),
|
|
76
75
|
// One hydrated author is estimated at 112 bytes, so the second result node exceeds the budget.
|
|
77
|
-
memoryBudget:
|
|
76
|
+
memoryBudget: { warnBytes: 200, maxBytes: 200 },
|
|
78
77
|
query: GQL`
|
|
79
78
|
mutation {
|
|
80
79
|
first: createAuthor(data: {name: "John"}) { ok errors { type message } node { id } }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test } from 'bun:test'
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
2
|
import { execute } from '../../../../../src/test.js'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
4
|
import { Model } from '@contember/schema'
|
|
@@ -118,3 +118,46 @@ test('aliases', async () => {
|
|
|
118
118
|
},
|
|
119
119
|
})
|
|
120
120
|
})
|
|
121
|
+
|
|
122
|
+
test('aliases named like Object.prototype members', async () => {
|
|
123
|
+
await execute({
|
|
124
|
+
schema: new SchemaBuilder()
|
|
125
|
+
.entity('Post', entity => entity.column('title', column => column.type(Model.ColumnType.String)))
|
|
126
|
+
.buildSchema(),
|
|
127
|
+
query: GQL`
|
|
128
|
+
query {
|
|
129
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
130
|
+
toString: title
|
|
131
|
+
constructor: title
|
|
132
|
+
__proto__: _meta {
|
|
133
|
+
title {
|
|
134
|
+
readable
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}`,
|
|
139
|
+
executes: [
|
|
140
|
+
{
|
|
141
|
+
sql: SQL`select
|
|
142
|
+
"root_"."title" as "root_toString",
|
|
143
|
+
"root_"."title" as "root_constructor",
|
|
144
|
+
"root_"."id" as "root_id"
|
|
145
|
+
from "public"."post" as "root_"
|
|
146
|
+
where "root_"."id" = ?`,
|
|
147
|
+
response: { rows: [{ root_toString: 'Hello', root_constructor: 'World' }] },
|
|
148
|
+
parameters: [testUuid(1)],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
return: {
|
|
152
|
+
data: {
|
|
153
|
+
getPost: JSON.parse('{"toString":"Hello","constructor":"World","__proto__":{"title":{"readable":true}}}'),
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
// graphql-js builds the query tree with a plain object, where these aliases hit Object.prototype
|
|
157
|
+
graphqlJsReturn: {
|
|
158
|
+
errors: [{ message: 'GraphQlQueryAstFactory: cannot merge Function and FieldNode' }],
|
|
159
|
+
data: { getPost: null },
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
expect(Object.hasOwn(Object.prototype, 'title')).toBe(false)
|
|
163
|
+
})
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { graphql,
|
|
1
|
+
import { graphql, GraphQLSchema, printSchema, validateSchema } from 'graphql'
|
|
2
2
|
import { Acl, Model } from '@contember/schema'
|
|
3
3
|
import * as fs from 'node:fs/promises'
|
|
4
4
|
import * as path from 'node:path'
|
|
5
5
|
import { AllowAllPermissionFactory, c, createSchema, SchemaBuilder, SchemaDefinition, SchemaDefinition as def } from '@contember/schema-definition'
|
|
6
|
-
import { Authorizator, GraphQlSchemaBuilderFactory, PermissionFactory } from '../../../../src/index.js'
|
|
6
|
+
import { Authorizator, GraphQlSchemaBuilderFactory, JsonContentSchemaBuilder, PermissionFactory } from '../../../../src/index.js'
|
|
7
|
+
import { toGraphQLJsSchema } from '@contember/graphql-json'
|
|
7
8
|
import * as model from './model.js'
|
|
8
9
|
import { SchemaValidator } from '@contember/schema-utils'
|
|
9
10
|
import { describe, expect, it } from 'bun:test'
|
|
@@ -22,30 +23,21 @@ interface Test {
|
|
|
22
23
|
const testSchema = async (test: Test) => {
|
|
23
24
|
const schemaResult = test.schema(new SchemaBuilder())
|
|
24
25
|
|
|
25
|
-
const schemaFactory = new GraphQlSchemaBuilderFactory()
|
|
26
26
|
const schema = schemaResult instanceof SchemaBuilder ? schemaResult.buildSchema() : schemaResult
|
|
27
27
|
const schemaWithAcl = { ...schema, acl: { roles: {}, variables: {} } }
|
|
28
28
|
const permissions = test.permissions(schemaWithAcl)
|
|
29
29
|
const rootPermissions = test.rootPermissions ? test.rootPermissions(schemaWithAcl) : permissions
|
|
30
30
|
const authorizator = new Authorizator(permissions, false, false)
|
|
31
31
|
const rootAuthorizator = new Authorizator(rootPermissions, false, false)
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
_info {
|
|
40
|
-
description
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
`,
|
|
44
|
-
})
|
|
45
|
-
const errors = (result.errors || []).map(it => it.message)
|
|
46
|
-
expect(errors).toStrictEqual([])
|
|
32
|
+
const graphQlJsSchema = new GraphQlSchemaBuilderFactory().create(schemaWithAcl, authorizator, rootAuthorizator).build()
|
|
33
|
+
const result = await graphql({ schema: graphQlJsSchema, source: '{ _info { description } }' })
|
|
34
|
+
expect((result.errors ?? []).map(it => it.message)).toStrictEqual([])
|
|
35
|
+
|
|
36
|
+
const jsonSchema = toGraphQLJsSchema(new JsonContentSchemaBuilder(schemaWithAcl, authorizator, rootAuthorizator).build().schema)
|
|
37
|
+
expect(validateSchema(jsonSchema).map(it => it.message)).toStrictEqual([])
|
|
47
38
|
|
|
48
|
-
|
|
39
|
+
// the files were recorded on main's graphql-js builder; clients see this exact SDL and order on both engines
|
|
40
|
+
const textSchema = printSchema(graphQlJsSchema) + '\n'
|
|
49
41
|
|
|
50
42
|
const filename = path.join(dirname(fileURLToPath(import.meta.url)), test.graphQlSchemaFile)
|
|
51
43
|
let expectedSchema: string
|
|
@@ -55,9 +47,8 @@ const testSchema = async (test: Test) => {
|
|
|
55
47
|
await fs.writeFile(filename, textSchema, { encoding: 'utf8' })
|
|
56
48
|
throw new Error(`Schema file ${filename} not found, creating with current schema`)
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
50
|
+
expect(textSchema).toStrictEqual(expectedSchema)
|
|
51
|
+
expect(printSchema(jsonSchema) + '\n').toStrictEqual(expectedSchema)
|
|
61
52
|
}
|
|
62
53
|
describe('GraphQL schema builder', () => {
|
|
63
54
|
it('column types', async () => {
|
|
@@ -453,13 +444,18 @@ describe('GraphQL schema builder', () => {
|
|
|
453
444
|
it('root writes that locate a row need a read grant in the nested set', async () => {
|
|
454
445
|
const schema = createSchema(RootWriteLookupRead)
|
|
455
446
|
const { root, all } = new PermissionFactory().createContextual(schema, ['editor'])
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
447
|
+
const authorizator = new Authorizator(all, false, false)
|
|
448
|
+
const rootAuthorizator = new Authorizator(root, false, false)
|
|
449
|
+
const schemas: GraphQLSchema[] = [
|
|
450
|
+
new GraphQlSchemaBuilderFactory().create(schema.model, authorizator, rootAuthorizator).build(),
|
|
451
|
+
toGraphQLJsSchema(new JsonContentSchemaBuilder(schema.model, authorizator, rootAuthorizator).build().schema),
|
|
452
|
+
]
|
|
453
|
+
|
|
454
|
+
for (const graphQlSchema of schemas) {
|
|
455
|
+
const mutationNames = Object.keys(graphQlSchema.getMutationType()?.getFields() ?? {})
|
|
456
|
+
expect(mutationNames.filter(it => it.endsWith('Comment'))).toStrictEqual(['createComment', 'deleteComment', 'updateComment', 'upsertComment'])
|
|
457
|
+
expect(mutationNames.filter(it => it.endsWith('Note'))).toStrictEqual(['createNote'])
|
|
458
|
+
}
|
|
463
459
|
})
|
|
464
460
|
|
|
465
461
|
it('array', async () => {
|
package/tests/src/test.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Acl, Model, Schema, Settings, Validation } from '@contember/schema'
|
|
2
|
-
import { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '../../src/index.js'
|
|
2
|
+
import { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory, JsonContentSchemaBuilder } from '../../src/index.js'
|
|
3
3
|
import { AllowAllPermissionFactory, emptySchema } from '@contember/schema-utils'
|
|
4
|
-
import {
|
|
5
|
-
import { Client, emptyDatabaseMetadata, RequestMemoryBudget } from '@contember/database'
|
|
4
|
+
import { assertGraphQlTestResult, GraphQlTestSchema, normalizeGraphQlResult, runGraphQlTest, serializeGraphQlResult } from './testGraphql.js'
|
|
5
|
+
import { Client, emptyDatabaseMetadata, RequestMemoryBudget, RequestMemoryBudgetOptions } from '@contember/database'
|
|
6
6
|
import { createConnectionMock } from '@contember/database-tester'
|
|
7
|
+
import { expect } from 'bun:test'
|
|
7
8
|
import { createUuidGenerator, testUuid } from './testUuid.js'
|
|
8
9
|
|
|
9
10
|
export interface SqlQuery {
|
|
@@ -22,9 +23,13 @@ export interface Test {
|
|
|
22
23
|
variables?: Acl.VariablesMap
|
|
23
24
|
query: string
|
|
24
25
|
queryVariables?: Record<string, any>
|
|
25
|
-
|
|
26
|
+
/** Each engine run gets its own budget: an exceeded budget stays exceeded. */
|
|
27
|
+
memoryBudget?: RequestMemoryBudgetOptions
|
|
26
28
|
executes: SqlQuery[]
|
|
29
|
+
/** The graphql-json response; also the graphql-js one unless `graphqlJsReturn` is set. */
|
|
27
30
|
return: object
|
|
31
|
+
/** A known difference: graphql-js answers this instead (errors reduced to their messages). */
|
|
32
|
+
graphqlJsReturn?: object
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
const SQL_BEGIN = {
|
|
@@ -77,16 +82,45 @@ export const failedTransaction = (executes: SqlQuery[]): SqlQuery[] => {
|
|
|
77
82
|
]
|
|
78
83
|
}
|
|
79
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Runs the request on graphql-js, as clients get it by default, and on graphql-json. Both must answer with the same bytes
|
|
87
|
+
* (key order and errors included) and leave the same expected queries unused; then the answer is checked against `return`.
|
|
88
|
+
*/
|
|
80
89
|
export const execute = async (test: Test) => {
|
|
81
90
|
const permissions: Acl.Permissions = test.permissions || new AllowAllPermissionFactory().create(test.schema)
|
|
82
91
|
// Mirror production (GraphQlSchemaFactory): types are shaped by the nested set, root fields by the root set.
|
|
83
92
|
const nestedPermissions: Acl.Permissions = test.nestedPermissions ?? permissions
|
|
84
93
|
const authorizator = new Authorizator(nestedPermissions, false, false)
|
|
85
94
|
const rootAuthorizator = new Authorizator(permissions, false, false)
|
|
86
|
-
const builder = new GraphQlSchemaBuilderFactory().create(test.schema, authorizator, rootAuthorizator)
|
|
87
|
-
const graphQLSchema = builder.build()
|
|
88
95
|
|
|
89
|
-
const
|
|
96
|
+
const graphqlJs = await executeOnEngine(test, permissions, nestedPermissions, {
|
|
97
|
+
engine: 'graphql-js',
|
|
98
|
+
schema: new GraphQlSchemaBuilderFactory().create(test.schema, authorizator, rootAuthorizator).build(),
|
|
99
|
+
})
|
|
100
|
+
const graphqlJson = await executeOnEngine(test, permissions, nestedPermissions, {
|
|
101
|
+
engine: 'graphql-json',
|
|
102
|
+
schema: new JsonContentSchemaBuilder(test.schema, authorizator, rootAuthorizator).build(),
|
|
103
|
+
})
|
|
104
|
+
if (test.graphqlJsReturn) {
|
|
105
|
+
expect(normalizeGraphQlResult(graphqlJs.result)).toStrictEqual(test.graphqlJsReturn)
|
|
106
|
+
assertGraphQlTestResult(graphqlJson.result, test.return)
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
expect(graphqlJson.serialized).toBe(graphqlJs.serialized)
|
|
110
|
+
expect(graphqlJson.unusedQueries).toBe(graphqlJs.unusedQueries)
|
|
111
|
+
|
|
112
|
+
assertGraphQlTestResult(graphqlJs.result, test.return)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const executeOnEngine = async (
|
|
116
|
+
test: Test,
|
|
117
|
+
permissions: Acl.Permissions,
|
|
118
|
+
nestedPermissions: Acl.Permissions,
|
|
119
|
+
graphQLSchema: GraphQlTestSchema,
|
|
120
|
+
) => {
|
|
121
|
+
// the mock consumes the list, and a run must not see rows the other run's hydration touched
|
|
122
|
+
const expectedQueries = test.executes.map(it => ({ ...it, response: structuredClone(it.response) }))
|
|
123
|
+
const connection = createConnectionMock(expectedQueries)
|
|
90
124
|
|
|
91
125
|
const db = new Client(connection, 'public', {})
|
|
92
126
|
const schema: Schema = { ...emptySchema, model: test.schema, validation: test.validation || {}, settings: test.settings || emptySchema.settings }
|
|
@@ -102,7 +136,7 @@ export const execute = async (test: Test) => {
|
|
|
102
136
|
})
|
|
103
137
|
})
|
|
104
138
|
})
|
|
105
|
-
await
|
|
139
|
+
const result = await runGraphQlTest({
|
|
106
140
|
context: {
|
|
107
141
|
db: db,
|
|
108
142
|
identityVariables: test.variables || {},
|
|
@@ -115,7 +149,7 @@ export const execute = async (test: Test) => {
|
|
|
115
149
|
id: 1,
|
|
116
150
|
},
|
|
117
151
|
db,
|
|
118
|
-
memoryBudget: test.memoryBudget,
|
|
152
|
+
memoryBudget: test.memoryBudget ? new RequestMemoryBudget(test.memoryBudget) : undefined,
|
|
119
153
|
identityVariables: test.variables || {},
|
|
120
154
|
identityId: '00000000-0000-0000-0000-000000000000',
|
|
121
155
|
systemSchema: 'system',
|
|
@@ -128,7 +162,7 @@ export const execute = async (test: Test) => {
|
|
|
128
162
|
},
|
|
129
163
|
query: test.query,
|
|
130
164
|
queryVariables: test.queryVariables,
|
|
131
|
-
return: test.return,
|
|
132
165
|
schema: graphQLSchema,
|
|
133
166
|
})
|
|
167
|
+
return { result, serialized: serializeGraphQlResult(result), unusedQueries: expectedQueries.length }
|
|
134
168
|
}
|