cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Routing error when directly fetching properties on interfaces

Open alexus37 opened this issue 1 year ago • 5 comments

Component(s)

router

router version

v0.0.0-20240927172855-3e390cd5cf6c

What happened?

Description

The router is encountering an error when I try to retrieve the query plan for queries that directly fetch data from interfaces.

Steps to Reproduce

Execute a query like this:

{
  repository(name: "<REDACTED>", owner: "<REDACTED>") {
    issue(number: 1) {
      timelineItems(since: "<REDACTED>", first: 1) {
        edges {
          node {
            ... on Comment {
              id
              bodyText
            }
          }
        }
      }
    }
  }
}

where the Comment is an interface and not a type.

interface Comment {
  
  """
  The body rendered to text.
  """
  bodyText: String!

  """
  The Node ID of the Comment object
  """
  id: ID!
}

Expected Result

The correct query plan is being returned! This works perfectly when I directly fetch data from a type that implements that interface or when I simply retrieve the ID.

Actual Result

We are getting a execution plan failure.

Environment information

I am using the following headers:

{
  "X-WG-TRACE": "false",
  "X-WG-Skip-Loader": "true",
  "X-WG-Include-Query-Plan": "true",
}

Log output

AM ERROR internal error {"error": "1 error occurred:\n\t* could not resolve a field: internal: nodesResolvableVisitor: could not select the datasource to resolve Repository.__typename on path query.repository.__typename\n\n"}

alexus37 avatar Dec 13 '24 09:12 alexus37

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.

github-actions[bot] avatar Dec 13 '24 09:12 github-actions[bot]

I am facing similar issue as well where __typename required on interface object when fetching Id. If we are fetch other attributes of interface, then its working as expected.

For instance: SubGraph A

interface A {
  a1Field: ID!
  a2Field: String
  a3Field: String
}

type XA implements A {
  a1Field: ID!
  a2Field: String
  a3Field: String
  xa1Field: String
}

type XB implements A {
  a1Field: ID!
  a2Field: String
  a3Field: String
  xb1Field: String
}

SubGraph B

type B {
  b1Field: ID!
  b2Field: String
  a: A!
}

query details:

query Test {
  b(id: ID!) {
    b1Field
    b2Field
    a {
      a1Field
    }
  }
}

The above query returns following error: Subgraph 'B' returned invalid value 'A' for __typename field.

QueryPlan {
    SingleFetch(service: "B") {
        {
            b(id: $Id) {
                b1Field
                b2Field
                a {
                    __typename
                    a1Field
                }
            }
        }
    }
}

However, following queries returns data as expected

query Test {
  b(id: ID!) {
    b1Field: ID!
    b2Field: String
    a {
      a1Field
      a2Field
    }
  }
}

or

query Test {
  b(id: ID!) {
    b1Field: ID!
    b2Field: String
    a {
      __typename
      a1Field
    }
  }
}

apatelWU avatar Dec 19 '24 18:12 apatelWU

Noticed the same thing while creating repro for #1440.

YassineElbouchaibi avatar Dec 19 '24 20:12 YassineElbouchaibi

+1, preventing us from adopting Cosmo.

rlch avatar Feb 07 '25 00:02 rlch

Hi @alexus37 @apatelWU

please try out this version https://github.com/wundergraph/cosmo/releases/tag/router%400.175.1

Runtime error should no longer happen

@YassineElbouchaibi @rlch please try too, in case issue won't be resolved please create separate issues with the subgraph sdls and failing queries if any

devsergiy avatar Feb 12 '25 19:02 devsergiy

Hi, we still have the same error with router 0.214.0 + 0.215.1:

DGS-A

interface Node {
  id: ID!
}

type Article implements Node {
  id: ID!
  title: String
}

DGS-B


type Article @key(fields : "id") {
  id: ID! @external
  recommendations: RecommendationConnection! @requires(fields : "id")
}

type Query {
  recommendations(itemId: ID!): RecommendationConnection!
}

type RecommendationConnection {
  items: [RecommendationEntry]!
}

type RecommendationEntry {
  item: Article!
  score
}

Query:

query recoDemo {
  recommendations(itemId: "kmp:cms:VWh4TFJUbw") {
    __typename
    items {
      __typename
      item {
        __typename
        id
      }
    }
  }
}

Errors:

DEBUG core/graphql_prehandler.go:970 failed to plan operation 
{"hostname": "cosmo-router-playground-7456797776-54b6c", "pid": 1, "service": "@wundergraph/router", "service_version": "0.214.0", "request_id": "878bab0236eddd4acc84c57ab3589fac", "trace_id": "55a556437e16f2f9e60959545094db27", 
"error": "could not resolve a field: internal: nodesResolvableVisitor: could not select the datasource to resolve Article.id on path query.recommendations.items.item.id"}

DEBUG core/errors.go:308 operation error 
{"hostname": "cosmo-router-playground-7456797776-54b6c", "pid": 1, "service": "@wundergraph/router", "service_version": "0.214.0", "request_id": "878bab0236eddd4acc84c57ab3589fac", "trace_id": "55a556437e16f2f9e60959545094db27", 
"error": "could not resolve a field: internal: nodesResolvableVisitor: could not select the datasource to resolve Article.id on path query.recommendations.items.item.id"}

ERROR core/errors.go:102 internal error 
{"hostname": "cosmo-router-playground-7456797776-54b6c", "pid": 1, "service": "@wundergraph/router", "service_version": "0.214.0", "request_id": "878bab0236eddd4acc84c57ab3589fac", "trace_id": "55a556437e16f2f9e60959545094db27", 
"error": "1 error occurred:\n\t* could not resolve a field: internal: nodesResolvableVisitor: could not select the datasource to resolve Article.id on path query.recommendations.items.item.id\n\n"}

saerdnaer avatar May 27 '25 14:05 saerdnaer

Hi @saerdnaer

Could you provide complete schemas for your subgraphs? Or give us your execution config.json (please share here or in the discord)

Thanks, Wundergraph Team

devsergiy avatar May 27 '25 17:05 devsergiy

@devsergiy I sent you the complete subgraphs, how can i access the config.json?

saerdnaer avatar May 28 '25 08:05 saerdnaer

@saerdnaer config.json are result of running wgc router compose

devsergiy avatar May 28 '25 08:05 devsergiy

No activity for a long time, considering the issue was fixed

If you have any other problem, please create a separate issue

Thanks, Wundergraph Team

devsergiy avatar Jul 22 '25 15:07 devsergiy