Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Lists of object types in input types #6

Open
wellers opened this issue Apr 11, 2022 · 3 comments
Open

Using Lists of object types in input types #6

wellers opened this issue Apr 11, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@wellers
Copy link

wellers commented Apr 11, 2022

I am trying to run mutations like the following, passing an array of objects in my input parameters:

mutation {
    people_insert(input: { people: [{ name: "Bob", age: 25 }]}) { 
        success, 
        message
    } 
}

I have defined my schema inputs and return objects like so:

final personInsertInput = inputObjectType("person_input", inputFields: [
    inputField("name", graphQLString.nonNullable()),
    inputField("age", graphQLInt.nonNullable())
]);

final peopleInsertInput = inputObjectType("people_insert_input", inputFields: [
    inputField("people", listOf(personInsertInput.nonNullable()).nonNullable())
]);

final peopleInsertResult = objectType("people_insert_result", fields: [
    field("success", graphQLBoolean.nonNullable()),
    field("message", graphQLString.nonNullable())
]);

And a mutation object for inserting like this:

var mutationType = objectType("Mutation",
    fields:[      
      field(
        "people_insert",
        peopleInsertResult,
        inputs: [
          GraphQLFieldInput("input", peopleInsertInput)          
        ],
        resolve: (obj, args) async {
          // insert records from args
          return { 'success': true, 'message': 'record(s) inserted.' };
        }
      )]);

When I run the above mutation I get the following response:

{
  "errors": [
    {
      "message": "Type coercion error for value of argument \"input\" of field \"people_insert\". [{people: [{name: Bob, age: 25}]}]",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    },
    {
      "message": "type 'List<dynamic>' is not a subtype of type 'List<Map<String, dynamic>>' of 'input'",
      "locations": [
        {
          "line": 1,
          "column": 25
        }
      ]
    }
  ]
}

Have I missed something in my schema definitions or is this not possible yet?

@wellers
Copy link
Author

wellers commented Apr 11, 2022

Ideally I'd like to run mutations like this:

mutation($input: people_insert_input!) {
    people_insert(input: $input) { 
        success, 
        message
    } 
}

Passing variables like so:

{
   "input": {   
       "people" : [{
           "name": "Tom",
           "age": 25
       }]
   }
}

But this also results in an error:

{
    "errors": [
        {
            "message": "type 'List<dynamic>' is not a subtype of type 'List<Map<String, dynamic>>' of 'input'"
        }
    ]
}

@wellers
Copy link
Author

wellers commented Apr 11, 2022

I've found that if I change my peopleInsertInput to:

final peopleInsertInput = inputObjectType("people_insert_input", inputFields: [
    inputField("people", listOf(personInsertInput.nonNullable()))
]);

Mutations like this work now:

mutation {
    people_insert(input: { people: [{ name: "Bob", age: 25 }]}) { 
        success, 
        message
    } 
}

But if I try to run mutations like this (passing in the $input type):

mutation($input: people_insert_input!) {
    people_insert(input: $input) { 
        success, 
        message
    } 
}

I get a stack overflow exception on the GraphQL.makeLazy() method. Looks to be in an infinite loop in the recursive function.

@dukefirehawk dukefirehawk added the bug Something isn't working label Apr 18, 2022
@dukefirehawk
Copy link
Collaborator

Will take a look at this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants