@payloadcms/graphql 3.0.0-alpha.63 → 3.0.0-alpha.64
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/package.json +3 -3
- package/src/index.ts +0 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/graphql",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.64",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@types/pluralize": "^0.0.33",
|
|
22
22
|
"ts-essentials": "7.0.3",
|
|
23
23
|
"@payloadcms/eslint-config": "1.1.1",
|
|
24
|
-
"payload": "3.0.0-alpha.
|
|
24
|
+
"payload": "3.0.0-alpha.64"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"graphql": "16.8.1",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"pluralize": "8.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"payload": "3.0.0-alpha.
|
|
36
|
+
"payload": "3.0.0-alpha.64"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
package/src/index.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import type { OperationArgs } from 'graphql-http'
|
|
3
|
-
import type { GraphQLInfo } from 'payload/config'
|
|
4
|
-
import type { SanitizedConfig } from 'payload/types'
|
|
5
|
-
|
|
6
|
-
import * as GraphQL from 'graphql'
|
|
7
|
-
import {
|
|
8
|
-
createComplexityRule,
|
|
9
|
-
fieldExtensionsEstimator,
|
|
10
|
-
simpleEstimator,
|
|
11
|
-
} from 'graphql-query-complexity'
|
|
12
|
-
|
|
13
|
-
import accessResolver from './resolvers/auth/access.js'
|
|
14
|
-
import buildFallbackLocaleInputType from './schema/buildFallbackLocaleInputType.js'
|
|
15
|
-
import buildLocaleInputType from './schema/buildLocaleInputType.js'
|
|
16
|
-
import buildPoliciesType from './schema/buildPoliciesType.js'
|
|
17
|
-
import initCollections from './schema/initCollections.js'
|
|
18
|
-
import initGlobals from './schema/initGlobals.js'
|
|
19
|
-
import { wrapCustomFields } from './utilities/wrapCustomResolver.js'
|
|
20
|
-
|
|
21
|
-
export async function configToSchema(config: SanitizedConfig): Promise<{
|
|
22
|
-
schema: GraphQL.GraphQLSchema
|
|
23
|
-
validationRules: (args: OperationArgs<any>) => GraphQL.ValidationRule[]
|
|
24
|
-
}> {
|
|
25
|
-
const collections = config.collections.reduce((acc, collection) => {
|
|
26
|
-
acc[collection.slug] = {
|
|
27
|
-
config: collection,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return acc
|
|
31
|
-
}, {})
|
|
32
|
-
|
|
33
|
-
const globals = {
|
|
34
|
-
config: config.globals,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const graphqlResult: GraphQLInfo = {
|
|
38
|
-
Mutation: {
|
|
39
|
-
name: 'Mutation',
|
|
40
|
-
fields: {},
|
|
41
|
-
},
|
|
42
|
-
Query: {
|
|
43
|
-
name: 'Query',
|
|
44
|
-
fields: {},
|
|
45
|
-
},
|
|
46
|
-
collections,
|
|
47
|
-
globals,
|
|
48
|
-
types: {
|
|
49
|
-
arrayTypes: {},
|
|
50
|
-
blockInputTypes: {},
|
|
51
|
-
blockTypes: {},
|
|
52
|
-
groupTypes: {},
|
|
53
|
-
tabTypes: {},
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (config.localization) {
|
|
58
|
-
graphqlResult.types['localeInputType'] = buildLocaleInputType(config.localization)
|
|
59
|
-
graphqlResult.types['fallbackLocaleInputType'] = buildFallbackLocaleInputType(
|
|
60
|
-
config.localization,
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
initCollections({ config, graphqlResult })
|
|
65
|
-
initGlobals({ config, graphqlResult })
|
|
66
|
-
|
|
67
|
-
graphqlResult.Query.fields['Access'] = {
|
|
68
|
-
type: buildPoliciesType(config),
|
|
69
|
-
resolve: accessResolver(config),
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (typeof config.graphQL.queries === 'function') {
|
|
73
|
-
const customQueries = config.graphQL.queries(GraphQL, {
|
|
74
|
-
...graphqlResult,
|
|
75
|
-
config,
|
|
76
|
-
})
|
|
77
|
-
graphqlResult.Query = {
|
|
78
|
-
...graphqlResult.Query,
|
|
79
|
-
fields: {
|
|
80
|
-
...graphqlResult.Query.fields,
|
|
81
|
-
...wrapCustomFields((customQueries || {}) as never),
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (typeof config.graphQL.mutations === 'function') {
|
|
87
|
-
const customMutations = config.graphQL.mutations(GraphQL, {
|
|
88
|
-
...graphqlResult,
|
|
89
|
-
config,
|
|
90
|
-
})
|
|
91
|
-
graphqlResult.Mutation = {
|
|
92
|
-
...graphqlResult.Mutation,
|
|
93
|
-
fields: {
|
|
94
|
-
...graphqlResult.Mutation.fields,
|
|
95
|
-
...wrapCustomFields((customMutations || {}) as never),
|
|
96
|
-
},
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const query = new GraphQL.GraphQLObjectType(graphqlResult.Query)
|
|
101
|
-
const mutation = new GraphQL.GraphQLObjectType(graphqlResult.Mutation)
|
|
102
|
-
|
|
103
|
-
const schemaToCreate = {
|
|
104
|
-
mutation,
|
|
105
|
-
query,
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const schema = new GraphQL.GraphQLSchema(schemaToCreate)
|
|
109
|
-
|
|
110
|
-
const validationRules = (args) => [
|
|
111
|
-
createComplexityRule({
|
|
112
|
-
estimators: [
|
|
113
|
-
fieldExtensionsEstimator(),
|
|
114
|
-
simpleEstimator({ defaultComplexity: 1 }), // Fallback if complexity not set
|
|
115
|
-
],
|
|
116
|
-
maximumComplexity: config.graphQL.maxComplexity,
|
|
117
|
-
variables: args.variableValues,
|
|
118
|
-
// onComplete: (complexity) => { console.log('Query Complexity:', complexity); },
|
|
119
|
-
}),
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
schema,
|
|
124
|
-
validationRules,
|
|
125
|
-
}
|
|
126
|
-
}
|