feat: graphql support for custom id types

This commit is contained in:
Dan Ribbens
2021-08-16 11:54:49 -04:00
parent 114dc1b3fb
commit bc2a6e1575
14 changed files with 337 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import {
GraphQLEnumType,
GraphQLFloat,
GraphQLInputObjectType,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
@@ -16,6 +17,17 @@ import formatName from '../utilities/formatName';
import combineParentName from '../utilities/combineParentName';
import { ArrayField, Field, FieldWithSubFields, GroupField, RelationshipField, RowField, SelectField } from '../../fields/config/types';
import { toWords } from '../../utilities/formatLabels';
import payload from '../../index';
const getCollectionIDType = (id) => {
switch (id) {
case Number:
return GraphQLInt;
default:
return GraphQLString;
}
};
function buildMutationInputType(name: string, fields: Field[], parentName: string, forceNullable = false): GraphQLInputObjectType {
const fieldToSchemaMap = {
@@ -85,9 +97,11 @@ function buildMutationInputType(name: string, fields: Field[], parentName: strin
}), {}),
}),
},
value: { type: GraphQLString },
value: { type: GraphQLJSON },
},
});
} else {
type = getCollectionIDType(payload.collections[relationTo].config.id);
}
return { type: field.hasMany ? new GraphQLList(type) : type };

View File

@@ -344,7 +344,7 @@ const buildWhereInputType = (name: string, fields: Field[], parentName: string):
fieldTypes.id = {
type: withOperators(
{ name: 'id' } as Field,
GraphQLString,
GraphQLJSON,
parentName,
[...operators.equality, ...operators.contains],
),