Merge pull request #302 from trouble/hotfix/299
adds createdAt and updatedAt to GraphQL
This commit is contained in:
@@ -28,6 +28,7 @@ function registerCollections() {
|
||||
plural,
|
||||
},
|
||||
fields: initialFields,
|
||||
timestamps,
|
||||
},
|
||||
} = collection;
|
||||
|
||||
@@ -48,18 +49,48 @@ function registerCollections() {
|
||||
|
||||
collection.graphQL = {};
|
||||
|
||||
const baseFields = {
|
||||
id: {
|
||||
type: new GraphQLNonNull(GraphQLString),
|
||||
},
|
||||
};
|
||||
|
||||
const whereInputFields = [
|
||||
...fields,
|
||||
];
|
||||
|
||||
if (timestamps) {
|
||||
baseFields.createdAt = {
|
||||
type: new GraphQLNonNull(GraphQLString),
|
||||
};
|
||||
|
||||
baseFields.updatedAt = {
|
||||
type: new GraphQLNonNull(GraphQLString),
|
||||
};
|
||||
|
||||
whereInputFields.push({
|
||||
name: 'createdAt',
|
||||
label: 'Created At',
|
||||
type: 'date',
|
||||
});
|
||||
|
||||
whereInputFields.push({
|
||||
name: 'updatedAt',
|
||||
label: 'Upated At',
|
||||
type: 'date',
|
||||
});
|
||||
}
|
||||
|
||||
collection.graphQL.type = this.buildObjectType(
|
||||
singularLabel,
|
||||
fields,
|
||||
singularLabel,
|
||||
{
|
||||
id: { type: GraphQLString },
|
||||
},
|
||||
baseFields,
|
||||
);
|
||||
|
||||
collection.graphQL.whereInputType = this.buildWhereInputType(
|
||||
singularLabel,
|
||||
fields,
|
||||
whereInputFields,
|
||||
singularLabel,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
const { GraphQLNonNull } = require('graphql');
|
||||
|
||||
const withNullableType = (field, type) => {
|
||||
if (field.required && !field.localized) {
|
||||
const hasReadAccessControl = field.access && field.access.read;
|
||||
|
||||
if (field.required && !field.localized && !hasReadAccessControl) {
|
||||
return new GraphQLNonNull(type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user