From cfffe52e888dcbd1d00f6c3abbfb862cbc87bd1c Mon Sep 17 00:00:00 2001 From: James Date: Sun, 12 Apr 2020 15:18:31 -0400 Subject: [PATCH] enables conditional ID addition to buildObjectType --- src/collections/graphql/register.js | 2 +- src/graphql/schema/buildObjectType.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/collections/graphql/register.js b/src/collections/graphql/register.js index 97762ca706..679e3b16f2 100644 --- a/src/collections/graphql/register.js +++ b/src/collections/graphql/register.js @@ -32,7 +32,7 @@ function registerCollections() { singularLabel, fields, singularLabel, - getFindByID(this.config, collection), + true, ); collection.graphQL.whereInputType = this.buildWhereInputType( diff --git a/src/graphql/schema/buildObjectType.js b/src/graphql/schema/buildObjectType.js index bf02de8fbb..a4948bc122 100644 --- a/src/graphql/schema/buildObjectType.js +++ b/src/graphql/schema/buildObjectType.js @@ -17,7 +17,7 @@ const combineParentName = require('../utilities/combineParentName'); const withNullableType = require('./withNullableType'); const find = require('../../collections/queries/find'); -function buildObjectType(name, fields, parentName) { +function buildObjectType(name, fields, parentName, addID) { const fieldToSchemaMap = { number: field => ({ type: withNullableType(field, GraphQLFloat) }), text: field => ({ type: withNullableType(field, GraphQLString) }), @@ -241,6 +241,9 @@ function buildObjectType(name, fields, parentName) { }, }; + const baseFields = {}; + if (addID) baseFields.id = { type: GraphQLString }; + const objectSchema = { name, fields: () => fields.reduce((schema, field) => { @@ -253,9 +256,7 @@ function buildObjectType(name, fields, parentName) { } return schema; - }, { - id: { type: GraphQLString }, - }), + }, baseFields), }; const newlyCreatedBlockType = new GraphQLObjectType(objectSchema);