gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Unexpected response for inline spread

Open romshark opened this issue 3 years ago • 2 comments

What happened?

The server returned an unexpected response for query А:

query A {
  todos {
    ... {
      id
      text
      user {
        id
      }
    }
  }
}

query B {
  todos {
    id
    text
    user {
      id
    }
  }
}

The response is broken:

{
  "data": {
    "todos": [
      {},
      {}
    ]
  }
}

Adding the ... @include(if:true) { directive doesn't help.

What did you expect?

I expect the same result as for query B:

{
  "data": {
    "todos": [
      {
        "id": "first",
        "text": "This is the first todo",
        "user": {
          "id": "first_creator"
        }
      },
      {
        "id": "second",
        "text": "This is the second todo",
        "user": {
          "id": "second_creator"
        }
      }
    ]
  }
}

Minimal graphql.schema and models to reproduce

# GraphQL schema example
#
# https://gqlgen.com/getting-started/

type Todo {
  id: ID!
  text: String!
  done: Boolean!
  user: User!
}

type User {
  id: ID!
  name: String!
}

type Query {
  todos: [Todo!]!
}

input NewTodo {
  text: String!
  userId: String!
}

type Mutation {
  createTodo(input: NewTodo!): Todo!
}

versions

  • go run github.com/99designs/gqlgen version: v0.17.7
  • go version: go1.18.2 linux/amd64

romshark avatar May 24 '22 19:05 romshark

Can you please create a Github repo for reproduction? Thanks.

frederikhors avatar May 24 '22 20:05 frederikhors

https://github.com/romshark/gqlgen-2195-reproduction @frederikhors you're welcome

romshark avatar May 24 '22 21:05 romshark