Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
fix(codegen-schema): map String list to String list in input type
Browse files Browse the repository at this point in the history
  • Loading branch information
Enda Phelan committed Nov 10, 2020
1 parent f74c958 commit 625a513
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines */
import { GraphQLInputObjectType, GraphQLList, GraphQLBoolean, GraphQLInt, GraphQLString, GraphQLID, GraphQLEnumType, GraphQLObjectType, GraphQLNonNull, GraphQLField, getNamedType, isScalarType, GraphQLInputFieldMap, GraphQLScalarType, GraphQLNamedType, GraphQLInputField, isEnumType, isObjectType, isInputObjectType, GraphQLInputType, getNullableType } from "graphql";
import { GraphQLInputObjectType, GraphQLList, GraphQLBoolean, GraphQLInt, GraphQLString, GraphQLID, GraphQLEnumType, GraphQLObjectType, GraphQLNonNull, GraphQLField, getNamedType, isScalarType, GraphQLInputFieldMap, GraphQLScalarType, GraphQLNamedType, GraphQLInputField, isEnumType, isObjectType, isInputObjectType, GraphQLInputType, getNullableType, isListType } from "graphql";
import { GraphbackOperationType, getInputTypeName, getInputFieldName, getInputFieldTypeName, isOneToManyField, getPrimaryKey, metadataMap, ModelDefinition, FILTER_SUPPORTED_SCALARS, isTransientField, isAutoPrimaryKey } from '@graphback/core';
import { SchemaComposer } from 'graphql-compose';
import { copyWrappingType } from './copyWrappingType';
Expand Down Expand Up @@ -265,10 +265,14 @@ export const buildMutationInputType = (schemaComposer: SchemaComposer<any>, mode
fields: () => {
const fields: any = {};
for (const { name, type } of allModelFields) {
let fieldType: GraphQLNamedType
let fieldType: GraphQLInputType

if (name !== idField.name) {
fieldType = getNamedType(type);
fieldType = getNullableType(type);
}

if (isListType(fieldType)) {
fieldType = GraphQLList(getNamedType(fieldType))
}

fields[name] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ Object {
"createComment": [Function],
"createFix": [Function],
"createIssue": [Function],
"createModelWithArrayScalar": [Function],
"createModelWithTransientField": [Function],
"createNote": [Function],
"createTest": [Function],
"createVersioned": [Function],
"deleteComment": [Function],
"deleteModelWithArrayScalar": [Function],
"deleteModelWithTransientField": [Function],
"deleteNote": [Function],
"deleteTest": [Function],
"updateComment": [Function],
"updateModelWithArrayScalar": [Function],
"updateModelWithTransientField": [Function],
"updateNote": [Function],
"updateTest": [Function],
Expand All @@ -119,11 +122,13 @@ Object {
},
"Query": Object {
"findComments": [Function],
"findModelWithArrayScalars": [Function],
"findModelWithTransientFields": [Function],
"findNotes": [Function],
"findTests": [Function],
"findVersioneds": [Function],
"getComment": [Function],
"getModelWithArrayScalar": [Function],
"getModelWithTransientField": [Function],
"getNote": [Function],
"getTest": [Function],
Expand All @@ -132,6 +137,9 @@ Object {
"deletedComment": Object {
"subscribe": [Function],
},
"deletedModelWithArrayScalar": Object {
"subscribe": [Function],
},
"deletedModelWithTransientField": Object {
"subscribe": [Function],
},
Expand All @@ -144,6 +152,9 @@ Object {
"newComment": Object {
"subscribe": [Function],
},
"newModelWithArrayScalar": Object {
"subscribe": [Function],
},
"newModelWithTransientField": Object {
"subscribe": [Function],
},
Expand All @@ -156,6 +167,9 @@ Object {
"updatedComment": Object {
"subscribe": [Function],
},
"updatedModelWithArrayScalar": Object {
"subscribe": [Function],
},
"updatedModelWithTransientField": Object {
"subscribe": [Function],
},
Expand Down Expand Up @@ -347,6 +361,10 @@ input CreateIssueInput {
bugFixId: ID
}
input CreateModelWithArrayScalarInput {
roles: [String!]!
}
input CreateModelWithTransientFieldInput {
name: String
}
Expand Down Expand Up @@ -495,6 +513,35 @@ input IssueFilter {
not: IssueFilter
}
\\"\\"\\"@model\\"\\"\\"
type ModelWithArrayScalar {
id: ID!
roles: [String!]!
}
input ModelWithArrayScalarFilter {
id: IDInput
roles: StringInput
and: [ModelWithArrayScalarFilter!]
or: [ModelWithArrayScalarFilter!]
not: ModelWithArrayScalarFilter
}
type ModelWithArrayScalarResultList {
items: [ModelWithArrayScalar]!
offset: Int
limit: Int
count: Int
}
input ModelWithArrayScalarSubscriptionFilter {
and: [ModelWithArrayScalarSubscriptionFilter!]
or: [ModelWithArrayScalarSubscriptionFilter!]
not: ModelWithArrayScalarSubscriptionFilter
id: IDInput
roles: StringInput
}
\\"\\"\\"@model\\"\\"\\"
type ModelWithTransientField {
id: ID!
Expand Down Expand Up @@ -535,6 +582,11 @@ input MutateCommentInput {
note_id: ID
}
input MutateModelWithArrayScalarInput {
id: ID!
roles: [String]
}
input MutateModelWithTransientFieldInput {
id: ID!
name: String
Expand Down Expand Up @@ -576,6 +628,9 @@ type Mutation {
createModelWithTransientField(input: CreateModelWithTransientFieldInput!): ModelWithTransientField
updateModelWithTransientField(input: MutateModelWithTransientFieldInput!): ModelWithTransientField
deleteModelWithTransientField(input: MutateModelWithTransientFieldInput!): ModelWithTransientField
createModelWithArrayScalar(input: CreateModelWithArrayScalarInput!): ModelWithArrayScalar
updateModelWithArrayScalar(input: MutateModelWithArrayScalarInput!): ModelWithArrayScalar
deleteModelWithArrayScalar(input: MutateModelWithArrayScalarInput!): ModelWithArrayScalar
}
\\"\\"\\" @model \\"\\"\\"
Expand Down Expand Up @@ -638,6 +693,8 @@ type Query {
findVersioneds(filter: VersionedFilter, page: PageRequest, orderBy: OrderByInput): VersionedResultList!
getModelWithTransientField(id: ID!): ModelWithTransientField
findModelWithTransientFields(filter: ModelWithTransientFieldFilter, page: PageRequest, orderBy: OrderByInput): ModelWithTransientFieldResultList!
getModelWithArrayScalar(id: ID!): ModelWithArrayScalar
findModelWithArrayScalars(filter: ModelWithArrayScalarFilter, page: PageRequest, orderBy: OrderByInput): ModelWithArrayScalarResultList!
}
enum SortDirectionEnum {
Expand Down Expand Up @@ -671,6 +728,9 @@ type Subscription {
newModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
updatedModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
deletedModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
newModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
updatedModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
deletedModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
}
\\"\\"\\"@model\\"\\"\\"
Expand Down Expand Up @@ -766,6 +826,8 @@ type Query {
findVersioneds(filter: VersionedFilter, page: PageRequest, orderBy: OrderByInput): VersionedResultList!
getModelWithTransientField(id: ID!): ModelWithTransientField
findModelWithTransientFields(filter: ModelWithTransientFieldFilter, page: PageRequest, orderBy: OrderByInput): ModelWithTransientFieldResultList!
getModelWithArrayScalar(id: ID!): ModelWithArrayScalar
findModelWithArrayScalars(filter: ModelWithArrayScalarFilter, page: PageRequest, orderBy: OrderByInput): ModelWithArrayScalarResultList!
}
\\"\\"\\" @model \\"\\"\\"
Expand Down Expand Up @@ -984,6 +1046,27 @@ input ModelWithTransientFieldFilter {
not: ModelWithTransientFieldFilter
}
\\"\\"\\"@model\\"\\"\\"
type ModelWithArrayScalar {
id: ID!
roles: [String!]!
}
type ModelWithArrayScalarResultList {
items: [ModelWithArrayScalar]!
offset: Int
limit: Int
count: Int
}
input ModelWithArrayScalarFilter {
id: IDInput
roles: StringInput
and: [ModelWithArrayScalarFilter!]
or: [ModelWithArrayScalarFilter!]
not: ModelWithArrayScalarFilter
}
type Mutation {
likeNote(id: ID!): Note!
createNote(input: CreateNoteInput!): Note
Expand All @@ -1002,6 +1085,9 @@ type Mutation {
createModelWithTransientField(input: CreateModelWithTransientFieldInput!): ModelWithTransientField
updateModelWithTransientField(input: MutateModelWithTransientFieldInput!): ModelWithTransientField
deleteModelWithTransientField(input: MutateModelWithTransientFieldInput!): ModelWithTransientField
createModelWithArrayScalar(input: CreateModelWithArrayScalarInput!): ModelWithArrayScalar
updateModelWithArrayScalar(input: MutateModelWithArrayScalarInput!): ModelWithArrayScalar
deleteModelWithArrayScalar(input: MutateModelWithArrayScalarInput!): ModelWithArrayScalar
}
input CreateNoteInput {
Expand Down Expand Up @@ -1162,6 +1248,15 @@ input MutateModelWithTransientFieldInput {
name: String
}
input CreateModelWithArrayScalarInput {
roles: [String!]!
}
input MutateModelWithArrayScalarInput {
id: ID!
roles: [String]
}
type Subscription {
newNote(filter: NoteSubscriptionFilter): Note!
updatedNote(filter: NoteSubscriptionFilter): Note!
Expand All @@ -1175,6 +1270,9 @@ type Subscription {
newModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
updatedModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
deletedModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
newModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
updatedModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
deletedModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
}
input NoteSubscriptionFilter {
Expand Down Expand Up @@ -1212,6 +1310,14 @@ input ModelWithTransientFieldSubscriptionFilter {
name: StringInput
}
input ModelWithArrayScalarSubscriptionFilter {
and: [ModelWithArrayScalarSubscriptionFilter!]
or: [ModelWithArrayScalarSubscriptionFilter!]
not: ModelWithArrayScalarSubscriptionFilter
id: IDInput
roles: StringInput
}
enum AUTH_ROLE {
ANONYMOUS
PRIVATE
Expand Down Expand Up @@ -1239,6 +1345,8 @@ type Query {
findVersioneds(filter: VersionedFilter, page: PageRequest, orderBy: OrderByInput): VersionedResultList!
getModelWithTransientField(id: ID!): ModelWithTransientField
findModelWithTransientFields(filter: ModelWithTransientFieldFilter, page: PageRequest, orderBy: OrderByInput): ModelWithTransientFieldResultList!
getModelWithArrayScalar(id: ID!): ModelWithArrayScalar
findModelWithArrayScalars(filter: ModelWithArrayScalarFilter, page: PageRequest, orderBy: OrderByInput): ModelWithArrayScalarResultList!
}
\\"\\"\\" @model \\"\\"\\"
Expand Down Expand Up @@ -1457,6 +1565,27 @@ input ModelWithTransientFieldFilter {
not: ModelWithTransientFieldFilter
}
\\"\\"\\"@model\\"\\"\\"
type ModelWithArrayScalar {
id: ID!
roles: [String!]!
}
type ModelWithArrayScalarResultList {
items: [ModelWithArrayScalar]!
offset: Int
limit: Int
count: Int
}
input ModelWithArrayScalarFilter {
id: IDInput
roles: StringInput
and: [ModelWithArrayScalarFilter!]
or: [ModelWithArrayScalarFilter!]
not: ModelWithArrayScalarFilter
}
type Mutation {
likeNote(id: ID!): Note!
createNote(input: CreateNoteInput!): Note
Expand All @@ -1475,6 +1604,9 @@ type Mutation {
createModelWithTransientField(input: CreateModelWithTransientFieldInput!): ModelWithTransientField
updateModelWithTransientField(input: MutateModelWithTransientFieldInput!): ModelWithTransientField
deleteModelWithTransientField(input: MutateModelWithTransientFieldInput!): ModelWithTransientField
createModelWithArrayScalar(input: CreateModelWithArrayScalarInput!): ModelWithArrayScalar
updateModelWithArrayScalar(input: MutateModelWithArrayScalarInput!): ModelWithArrayScalar
deleteModelWithArrayScalar(input: MutateModelWithArrayScalarInput!): ModelWithArrayScalar
}
input CreateNoteInput {
Expand Down Expand Up @@ -1635,6 +1767,15 @@ input MutateModelWithTransientFieldInput {
name: String
}
input CreateModelWithArrayScalarInput {
roles: [String!]!
}
input MutateModelWithArrayScalarInput {
id: ID!
roles: [String]
}
type Subscription {
newNote(filter: NoteSubscriptionFilter): Note!
updatedNote(filter: NoteSubscriptionFilter): Note!
Expand All @@ -1648,6 +1789,9 @@ type Subscription {
newModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
updatedModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
deletedModelWithTransientField(filter: ModelWithTransientFieldSubscriptionFilter): ModelWithTransientField!
newModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
updatedModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
deletedModelWithArrayScalar(filter: ModelWithArrayScalarSubscriptionFilter): ModelWithArrayScalar!
}
input NoteSubscriptionFilter {
Expand Down Expand Up @@ -1685,6 +1829,14 @@ input ModelWithTransientFieldSubscriptionFilter {
name: StringInput
}
input ModelWithArrayScalarSubscriptionFilter {
and: [ModelWithArrayScalarSubscriptionFilter!]
or: [ModelWithArrayScalarSubscriptionFilter!]
not: ModelWithArrayScalarSubscriptionFilter
id: IDInput
roles: StringInput
}
enum AUTH_ROLE {
ANONYMOUS
PRIVATE
Expand Down
6 changes: 6 additions & 0 deletions packages/graphback-codegen-schema/tests/mock.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@ type ModelWithTransientField {
scalar DateTime
scalar GraphbackDate
scalar GraphbackJSON

"""@model"""
type ModelWithArrayScalar {
id: ID!
roles: [String!]!
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Comment {
_id: GraphbackObjectID!
text: String
description: String
roles: [String!]!
}

type Query {
Expand Down

0 comments on commit 625a513

Please sign in to comment.