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

GraphQl Schema generates wrong Type for Relations #2058

Closed
athopen opened this issue Jun 29, 2018 · 3 comments
Closed

GraphQl Schema generates wrong Type for Relations #2058

athopen opened this issue Jun 29, 2018 · 3 comments

Comments

@athopen
Copy link

athopen commented Jun 29, 2018

Hello,

i have got a customer entity with a one-to-many-relation to an email-entity. Through the rest-api i am able to create the a new customer and the emails with a single request. Swagger already displays the correct arguments:

screenshot from 2018-06-29 11-46-18

But when i go to Graphiql it tells me that it expects an array of strings as an argument for the emails:

screenshot from 2018-06-29 11-51-11

The source of the problem is in the SchemaBuilder when the types are converted (https://github.com/api-platform/core/blob/master/src/GraphQl/Type/SchemaBuilder.php#L354). Because the input is true (createCustomerInput mutation) and the depth is 7 it always returns a GraphQl-StringType. I dont think that this is the right behaviour because the 7 isn´t the depth, its just the 7nth field.

When i do not increse the depth (https://github.com/api-platform/core/blob/master/src/GraphQl/Type/SchemaBuilder.php#L377) and just pass it to the function as it is the following mutation works and saves the customer including the emails.

Request:

mutation {
  createCustomer(
    input: {
      clientMutationId: "12", 
      firstName: "asdf", 
      lastName: "asdf", 
      emails: [
        {
          clientMutationId:"1", 
          email: "[email protected]", 
          primary: false
        }
      ]
    }
  ) {
    id
    emails {
      edges {
        node {
          id
          email
        }
      }
    }
  }
}

Result:

{
  "data": {
    "createCustomer": {
      "id": "/customers/5fe8afae-bc4a-4ba7-8418-01c4d1a00c78",
      "emails": {
        "edges": null
      }
    }
  }
}

But as you can see the Result does not contain the emails. If i send another request and try to get the customer directly the emails are present again.

Request:

{
  customer(id: "/customers/dcbfc05c-a72a-47d8-9111-fc5869831650") {
    firstName
    emails {
      edges {
        node {
          email
        }
      }
    }
  }
}

Response

{
  "data": {
    "customer": {
      "firstName": "asdf",
      "emails": {
        "edges": [
          {
            "node": {
              "email": "[email protected]"
            }
          }
        ]
      }
    }
  }
}

Am i missing some config or is this a bug?

@alanpoulain
Copy link
Member

This behavior is wanted. See #1964.
But depth should not be 7 and we should probably investigate this.

@leyriel
Copy link

leyriel commented Dec 16, 2018

Hello, do you have a news for this ? :)

@alanpoulain
Copy link
Member

The depth issue has been fixed. See #2612 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants