mirror of
https://github.com/strapi/strapi.git
synced 2025-08-30 11:45:48 +00:00
Add publicationState argument for graphql queries
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
ded8bc37bb
commit
0951e45d12
@ -226,6 +226,13 @@ You can also apply different parameters to the query to make more complex querie
|
||||
- `limit` (integer): Define the number of returned entries.
|
||||
- `start` (integer): Define the amount of entries to skip.
|
||||
- `sort` (string): Define how the data should be sorted.
|
||||
- `publicationState` (PublicationState): Only select entries matching the publication state provided.
|
||||
|
||||
Handled states are:
|
||||
|
||||
- `LIVE`: Return only published values (default)
|
||||
- `PREVIEW`: Return both draft & published entries
|
||||
|
||||
- `<field>:asc` or `<field>:desc`
|
||||
- `where` (object): Define the filters to apply in the query.
|
||||
- `<field>`: Equals.
|
||||
|
@ -14,6 +14,7 @@ const { buildModels } = require('./type-definitions');
|
||||
const { mergeSchemas, createDefaultSchema, diffResolvers } = require('./utils');
|
||||
const { toSDL } = require('./schema-definitions');
|
||||
const { buildQuery, buildMutation } = require('./resolvers-builder');
|
||||
const PublicationState = require('../types/publication-state');
|
||||
|
||||
/**
|
||||
* Generate GraphQL schema.
|
||||
@ -51,9 +52,12 @@ const generateSchema = () => {
|
||||
const mutationFields =
|
||||
shadowCRUD.mutation && toSDL(shadowCRUD.mutation, resolver.Mutation, null, 'mutation');
|
||||
|
||||
Object.assign(resolvers, PublicationState.resolver);
|
||||
|
||||
const scalars = Types.getScalars();
|
||||
|
||||
Object.assign(resolvers, scalars);
|
||||
|
||||
const scalarDef = Object.keys(scalars)
|
||||
.map(key => `scalar ${key}`)
|
||||
.join('\n');
|
||||
@ -66,6 +70,8 @@ const generateSchema = () => {
|
||||
|
||||
${Types.addInput()}
|
||||
|
||||
${PublicationState.definition}
|
||||
|
||||
type AdminUser {
|
||||
id: ID!
|
||||
username: String
|
||||
|
@ -7,7 +7,14 @@
|
||||
*/
|
||||
|
||||
const _ = require('lodash');
|
||||
<<<<<<< HEAD
|
||||
const { contentTypes } = require('strapi-utils');
|
||||
=======
|
||||
const {
|
||||
getPrivateAttributes,
|
||||
contentTypes: { hasDraftAndPublish },
|
||||
} = require('strapi-utils');
|
||||
>>>>>>> Add publicationState argument for graphql queries
|
||||
|
||||
const DynamicZoneScalar = require('../types/dynamiczoneScalar');
|
||||
|
||||
@ -397,9 +404,13 @@ const buildCollectionType = model => {
|
||||
..._.get(_schema, `resolver.Query.${pluralName}`, {}),
|
||||
};
|
||||
if (actionExists(resolverOpts)) {
|
||||
const draftAndPublishArgument = hasDraftAndPublish(model)
|
||||
? 'publicationState: PublicationState'
|
||||
: '';
|
||||
const params = `(sort: String, limit: Int, start: Int, where: JSON ${draftAndPublishArgument})`;
|
||||
_.merge(localSchema, {
|
||||
query: {
|
||||
[`${pluralName}(sort: String, limit: Int, start: Int, where: JSON)`]: `[${model.globalId}]`,
|
||||
[`${pluralName}${params}`]: `[${model.globalId}]`,
|
||||
},
|
||||
resolvers: {
|
||||
Query: {
|
||||
|
16
packages/strapi-plugin-graphql/types/publication-state.js
Normal file
16
packages/strapi-plugin-graphql/types/publication-state.js
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
definition: `
|
||||
enum PublicationState {
|
||||
LIVE
|
||||
PREVIEW
|
||||
}
|
||||
`,
|
||||
resolver: {
|
||||
PublicationState: {
|
||||
LIVE: 'live',
|
||||
PREVIEW: 'preview',
|
||||
},
|
||||
},
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user