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

[Reopened] Type resolver is invoked when reference resolver returns null for interface entity #3135

Open
aliosmanisikk opened this issue Sep 3, 2024 · 5 comments

Comments

@aliosmanisikk
Copy link

Issue Description

Reopening #3123

Issue Description

When __resolveReference returns null for interface entity, there is no need to invoke __resolveType. However, it is being invoked and causing issues with resolving type for null value.

I tested the behavior for Union or Interface type. For those, it works as expected. Issue occurs for Interface Entity only.

Link to Reproduction

https://github.com/aliosmanisikk/apollo-subgraph-interface-entity-type-resolver

Reproduction Steps

Running query for the shopping list where all products are resolved is fine.

query MyShoppingList {
  myShoppingList {
    items {
      id
      product {
        __typename
        slug
        type
      }
    }
  }
}

returns

{
  "data": {
    "myShoppingList": {
      "items": [
        {
          "id": "1",
          "product": {
            "__typename": "SunglassProduct",
            "slug": "sunglass-exists",
            "type": "SUNGLASS"
          }
        },
        {
          "id": "2",
          "product": {
            "__typename": "FrameProduct",
            "slug": "frame-exists",
            "type": "FRAME"
          }
        }
      ]
    }
  }
}

When there is a product in the shopping list which is no longer exists (entity resolves null), then an error is thrown by the subgraph.

query MyShoppingList {
  myStaleShoppingList {
    items {
      id
      product {
        __typename
        slug
        type
      }
    }
  }
}

returns

{
  "data": {
    "myStaleShoppingList": {
      "items": [
        {
          "id": "1",
          "product": {
            "__typename": "SunglassProduct",
            "slug": "sunglass-exists",
            "type": "SUNGLASS"
          }
        },
        {
          "id": "2",
          "product": null
        }
      ]
    }
  },
  "errors": [
    {
      "message": "Cannot read properties of null (reading 'type')",
      "path": [
        "myStaleShoppingList",
        "items",
        1,
        "product"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "TypeError: Cannot read properties of null (reading 'type')",
          "    at /Users/ali/WKS/test/apollo-subgraph-interface-entity-type-resolver/src/subgraph-a.ts:52:22",
          "    at Generator.next (<anonymous>)",
          "    at /Users/ali/WKS/test/apollo-subgraph-interface-entity-type-resolver/src/subgraph-a.ts:8:71",
          "    at new Promise (<anonymous>)",
          "    at __awaiter (/Users/ali/WKS/test/apollo-subgraph-interface-entity-type-resolver/src/subgraph-a.ts:4:12)",
          "    at __resolveType (/Users/ali/WKS/test/apollo-subgraph-interface-entity-type-resolver/src/subgraph-a.ts:51:69)",
          "    at withResolvedType (/Users/ali/WKS/test/apollo-subgraph-interface-entity-type-resolver/node_modules/@apollo/subgraph/src/types.ts:166:23)",
          "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
        ]
      }
    }
  ]
}
@aliosmanisikk
Copy link
Author

@dariuszkuc

FYI, reopened the issue with Federation and proper example.

@dariuszkuc
Copy link
Member

Thank for the repro! Indeed its a problem. We'll take a look.

dariuszkuc pushed a commit that referenced this issue Sep 3, 2024
Addresses #3123 / #3135 by skipping type resolution for `null`
references.
@dariuszkuc
Copy link
Member

This should be fixed in fed v2.9.1 that will be released this week.

@aliosmanisikk
Copy link
Author

Thanks @dariuszkuc . Looking forward to it.

@aliosmanisikk
Copy link
Author

I confirmed the fix with @apollo/subgraph@2.10.0-alpha.1

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

No branches or pull requests

2 participants