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

Values selection does not gracefully deal with missing fields within an array objects. #3972

Closed
o0Ignition0o opened this issue Oct 4, 2023 · 0 comments · Fixed by #3975
Closed
Assignees

Comments

@o0Ignition0o
Copy link
Contributor

Steps to reproduce:

Run this query:

query {
  stuff {
    id
    aDetailsIsEnabled
  }
}

Against a router with the schema pasted below.

The router will send a first query to SUB1:

{ "query": "{stuff{__typename id details{enabled}}}" }

Provide a response that has null elements in the details list:

{
  "data": {
    "stuff": {
      "__typename": "Stuff",
      "id": 12345,
      "details": [ 
        {"enabled": true},
        null,
        {"enabled": false}
      ]
    }
  }
}

Check the second subgraph request being made:

Expected (which is done in the gateway):

{
  "query": "query($representations:[_Any!]!){_entities(representations:$representations){...on Stuff{aDetailsIsEnabled}}}",
  "variables": {
    "representations": [
      {
        "__typename": "Stuff",
        "id": 12345,
        "details": [
          {
            "enabled": true
          },
          null,
          {
            "enabled": false
          }
        ]
      }
    ]
  }
}

Actual (in the router):

{
  "query": "query($representations:[_Any!]!){_entities(representations:$representations){...on Stuff{aDetailsIsEnabled}}}",
  "variables": {
    "representations": [
      {
        "__typename": "Stuff",
        "id": 12345
      }
    ]
  }
}

Details is missing in the router's representations because we failed to find the "enabled" field while selecting the relevant values in the selection set within the null items. We should use Value::Null in the array's item and keep processing them.

Schema for reference:

schema
  @link(url: "https://specs.apollo.dev/link/v1.0")
  @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
{
  query: Query
}

directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE

directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE

directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION

directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA

type Details
  @join__type(graph: SUB1)
  @join__type(graph: SUB2)
{
  enabled: Boolean
}

scalar join__FieldSet

enum join__Graph {
  SUB1 @join__graph(name: "sub1", url: "http://localhost:4002/test")
  SUB2 @join__graph(name: "sub2", url: "http://localhost:4002/test2")
}

scalar link__Import

enum link__Purpose {
  """
  `SECURITY` features provide metadata necessary to securely resolve fields.
  """
  SECURITY

  """
  `EXECUTION` features provide metadata necessary for operation execution.
  """
  EXECUTION
}

type Query
  @join__type(graph: SUB1)
  @join__type(graph: SUB2)
{
  stuff: Stuff @join__field(graph: SUB1)
}

type Stuff
  @join__type(graph: SUB1, key: "id")
  @join__type(graph: SUB2, key: "id", extension: true)
{
  id: ID
  details: [Details] @join__field(graph: SUB1) @join__field(graph: SUB2, external: true)
  aDetailsIsEnabled: Boolean @join__field(graph: SUB2, requires: "details { enabled }")
}
This was referenced Oct 17, 2023
Geal added a commit that referenced this issue Nov 30, 2023
related to #3972
Fix #3983 
Fix #4052

This rewrites the `@requires` selection code to better align with the gateway, and try to fill in the `__typename` if the information is missing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants