aerogear/graphback

One to many relationships returns null

b1zzu opened this issue · 0 comments

b1zzu commented

Graphback: 0.10.0-rc2
Database: sqlite in-memory

My schema

type Foo {
  id: ID!
  title: String!
  bars: [Bar]!
}

type Bar {
  id: ID!
  description: String!
}

I start the server and I create a new Foo

mutation {
  createFoo(input: { title: "test" }) {
    id
    title
  }
}

then if query all Foos the backend return null for bars:

query {
  findAllFoos {
    id
    title
    bars {
      id
      description
    }    
  }
}
{
  "data": {
    "findAllFoos": [
      {
        "id": "1",
        "title": "test",
        "bars": null
      }
    ]
  }
}

then I add a new Bar

mutation {
  createBar(input: { description: "rooo", fooId: 1 }) {
    id
    description
  }
}
{
  "data": {
    "createBar": {
      "id": "1",
      "description": "rooo"
    }
  }
}

if then I try to retrieve all Foos with the previous query, the result is unchanged:

{
  "data": {
    "findAllFoos": [
      {
        "id": "1",
        "title": "test",
        "bars": null
      }
    ]
  }
}

and if I try to query all bars with foos I get this error

{
  "error": {
    "errors": [
      {
        "message": "Field \"foo\" of type \"Foo!\" must have a selection of subfields. Did you mean \"foo { ... }\"?",
        "locations": [
          {
            "line": 5,
            "column": 5
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Field \"foo\" of type \"Foo!\" must have a selection of subfields. Did you mean \"foo { ... }\"?",
              "    at Object.Field (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/graphql/validation/rules/ScalarLeafs.js:45:31)",
              "    at Object.enter (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/graphql/language/visitor.js:324:29)",
              "    at Object.enter (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/graphql/language/visitor.js:375:25)",
              "    at visit (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/graphql/language/visitor.js:242:26)",
              "    at Object.validate (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/graphql/validation/validate.js:73:24)",
              "    at validate (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/apollo-server-core/src/requestPipeline.ts:427:22)",
              "    at Object.<anonymous> (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/apollo-server-core/src/requestPipeline.ts:253:32)",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled (/home/dbizzarr/Projects/github.com/aerogear/graphql-testx/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
              "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
            ]
          }
        }
      }
    ]
  }
}