payload 0.18.5 → 0.19.0

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +20 -2
  2. package/dist/admin/components/elements/DatePicker/DatePicker.js +3 -0
  3. package/dist/admin/components/elements/DatePicker/index.scss +17 -5
  4. package/dist/admin/components/forms/field-types/Relationship/createRelationMap.js +10 -4
  5. package/dist/admin/components/forms/field-types/Relationship/index.js +24 -6
  6. package/dist/admin/components/forms/field-types/Relationship/optionsReducer.js +12 -3
  7. package/dist/admin/components/forms/field-types/Relationship/types.d.ts +1 -0
  8. package/dist/admin/components/views/collections/List/Cell/field-types/Relationship/index.js +9 -2
  9. package/dist/auth/operations/access.js +1 -10
  10. package/dist/auth/strategies/jwt.js +3 -2
  11. package/dist/bin/generateGraphQLSchema.d.ts +1 -0
  12. package/dist/bin/generateGraphQLSchema.js +30 -0
  13. package/dist/bin/index.js +7 -2
  14. package/dist/collections/operations/local/create.d.ts +2 -0
  15. package/dist/collections/operations/local/create.js +3 -3
  16. package/dist/collections/operations/local/local.spec.js +22 -1
  17. package/dist/collections/operations/local/update.d.ts +1 -0
  18. package/dist/collections/operations/local/update.js +3 -3
  19. package/dist/collections/tests/collections.spec.js +92 -13
  20. package/dist/collections/tests/relationships.spec.js +13 -13
  21. package/dist/config/defaults.js +2 -1
  22. package/dist/config/schema.js +2 -1
  23. package/dist/config/types.d.ts +2 -1
  24. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +19 -17
  25. package/dist/fields/hooks/beforeChange/getExistingRowDoc.d.ts +7 -0
  26. package/dist/fields/hooks/beforeChange/getExistingRowDoc.js +17 -0
  27. package/dist/fields/hooks/beforeChange/promise.js +6 -5
  28. package/dist/fields/validations.js +3 -3
  29. package/dist/fields/validations.spec.js +43 -1
  30. package/dist/graphql/graphQLHandler.d.ts +9 -0
  31. package/dist/graphql/graphQLHandler.js +16 -0
  32. package/dist/graphql/registerSchema.d.ts +2 -0
  33. package/dist/graphql/{index.js → registerSchema.js} +7 -16
  34. package/dist/index.d.ts +3 -3
  35. package/dist/index.js +11 -5
  36. package/dist/mongoose/connect.js +2 -2
  37. package/docs/configuration/overview.mdx +2 -2
  38. package/docs/fields/relationship.mdx +2 -1
  39. package/docs/getting-started/concepts.mdx +5 -0
  40. package/docs/graphql/graphql-schema.mdx +53 -0
  41. package/docs/graphql/overview.mdx +13 -0
  42. package/docs/local-api/overview.mdx +4 -0
  43. package/package.json +3 -2
  44. package/dist/graphql/index.d.ts +0 -7
@@ -0,0 +1,53 @@
1
+ ---
2
+ title: GraphQL Schema
3
+ label: GraphQL Schema
4
+ order: 30
5
+ desc: Output your own GraphQL schema based on your collections and globals to a file.
6
+ keywords: headless cms, typescript, documentation, Content Management System, cms, headless, javascript, node, react, express
7
+ ---
8
+
9
+ When working with GraphQL it is useful to have the schema for development of other projects that need to call on your GraphQL endpoint. In Payload the schema is controlled by your collections and globals and is made available to the developer or third parties, it is not necessary for developers using Payload to write schema types manually.
10
+
11
+ ### GraphQL Schema generate script
12
+
13
+ Run the following command in a Payload project to generate your project's GraphQL schema from Payload:
14
+
15
+ ```
16
+ payload generate:graphQLSchema
17
+ ```
18
+
19
+ You can run this command whenever you need to regenerate your graphQL schema and output it to a file, and then you can use the schema for writing your own graphQL elsewhere in other projects.
20
+
21
+ ### GraphQL schema output file
22
+
23
+ ```js
24
+ {
25
+ // the remainder of your config
26
+ graphQL: {
27
+ schemaOutputFile: path.resolve(__dirname, './graphql/schema.graphql'),
28
+ },
29
+ }
30
+ ```
31
+
32
+ The above example outputs all your definitions to a file relative from your payload config as `./graphql/schema.graphql`. By default, the file will be output to your current working directory as `schema.graphql`.
33
+
34
+ #### Adding an NPM script
35
+
36
+ <Banner type="warning">
37
+ <strong>Important:</strong><br/>
38
+ Payload needs to be able to find your config to generate your GraphQL schema.
39
+ </Banner>
40
+
41
+ Payload will automatically try and locate your config, but might not always be able to find it. For example, if you are working in a `/src` directory or similar, you need to tell Payload where to find your config manually by using an environment variable. If this applies to you, you can create an NPM script to make generating your types easier.
42
+
43
+ To add an NPM script to generate your types and show Payload where to find your config, open your `package.json` and update the `scripts` property to the following:
44
+
45
+ ```json
46
+ {
47
+ "scripts": {
48
+ "generate:types": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
49
+ },
50
+ }
51
+ ```
52
+
53
+ Now you can run `yarn generate:graphQLSchema` to easily generate your schema.
@@ -12,6 +12,19 @@ By default, the GraphQL API is exposed via `/api/graphql`, but you can customize
12
12
 
13
13
  The labels you provide for your Collections and Globals are used to name the GraphQL types that are created to correspond to your config. Special characters and spaces are removed.
14
14
 
15
+ ## GraphQL Options
16
+
17
+ At the top of your Payload config you can define all the options to manage GraphQL. The
18
+
19
+ | Option | Description |
20
+ | -------------------- | -------------|
21
+ | `mutations` | Any custom Mutations to be added in addition to what Payload provides. [More](/docs/graphql/extending) |
22
+ | `queries` | Any custom Queries to be added in addition to what Payload provides. [More](/docs/graphql/extending) |
23
+ | `maxComplexity` | A number used to set the maximum allowed complexity allowed by requests [More](/docs/graphql/overview#query-complexity-limits) |
24
+ | `disablePlaygroundInProduction` | A boolean that if false will enable the graphQL playground, defaults to true. [More](/docs/graphql/overview#graphql-playground) |
25
+ | `disable` | A boolean that if false will disable the graphQL entirely, defaults to false. |
26
+ | `schemaOutputFile` | A string for the file path used by the generate schema command. Defaults to `graphql.schema` next to `payload.config.ts` [More](/docs/graphql/graphql-schema) |
27
+
15
28
  ## Collections
16
29
 
17
30
  Everything that can be done to a Collection via the REST or Local API can be done with GraphQL (outside of uploading files, which is REST-only). If you have a collection as follows:
@@ -102,6 +102,10 @@ const post = await payload.create({
102
102
  // a file directly through the Local API by providing
103
103
  // its full, absolute file path.
104
104
  filePath: path.resolve(__dirname, './path-to-image.jpg'),
105
+
106
+ // Alternatively, you can directly pass a File,
107
+ // if file is provided, filePath will be omitted
108
+ file: uploadedFile,
105
109
  })
106
110
  ```
107
111
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "0.18.5",
3
+ "version": "0.19.0",
4
4
  "description": "Node, React and MongoDB Headless CMS and Application Framework",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -27,7 +27,7 @@
27
27
  "payload": "bin.js"
28
28
  },
29
29
  "scripts": {
30
- "copyfiles": "copyfiles -u 1 src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png} dist/",
30
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
31
31
  "build:tsc": "tsc --p tsconfig.admin.json && tsc --p tsconfig.server.json",
32
32
  "build:components": "webpack --config dist/webpack/components.config.js",
33
33
  "build": "yarn copyfiles && yarn build:tsc && yarn build:components",
@@ -35,6 +35,7 @@
35
35
  "demo:build:analyze": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts PAYLOAD_ANALYZE_BUNDLE=true node dist/bin/build",
36
36
  "demo:build": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts node dist/bin/build",
37
37
  "demo:generate:types": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts node dist/bin/generateTypes",
38
+ "demo:generate:graphqlschema": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts node dist/bin/generateGraphQLSchema",
38
39
  "demo:serve": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts NODE_ENV=production nodemon",
39
40
  "dev": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts nodemon",
40
41
  "test": "yarn test:int && yarn test:client",
@@ -1,7 +0,0 @@
1
- /// <reference types="node" />
2
- declare const initializeGraphQL: (req: any, res: any) => (request: import("http").IncomingMessage & {
3
- url: string;
4
- }, response: import("http").ServerResponse & {
5
- json?: (data: unknown) => void;
6
- }) => Promise<void>;
7
- export default initializeGraphQL;