ardatan / graphql-mesh

🕸️ GraphQL Federation Framework for any API services such as REST, OpenAPI, Swagger, SOAP, gRPC and more...
https://the-guild.dev/graphql/mesh
MIT License
3.27k stars 340 forks source link

Unable to resolve the abstract type "BrandBaseConfigVo" in GraphQL Mesh #5320

Closed oaooao closed 5 months ago

oaooao commented 1 year ago

Description

I am trying to use GraphQL Mesh to convert an existing RESTful API into a GraphQL schema(Simplified version). I have generated the following schema, but when I run the query provided below, I receive an error in the response.

Schema(Simplified version)

type Query
  @globalOptions(
    sourceName: "CDP"
    endpoint: "{env.URL}/cdp-mgmt/v1/"
    operationHeaders: "{\"Authorization_Header\":\"{context.headers.authorization}\",\"Authorization_Cookie\":\"Bearer {context.cookies.accessToken}\"}"
  ) {
  brandConfig(
    brandId: String!
    type: String
  ): QueryCustomerConfigResponse
    @httpOperation(
      path: "/meta/{args.brandId}/config"
      operationSpecificHeaders: "{\"accept\":\"application/json\"}"
      httpMethod: GET
      queryParamArgMap: "{\"type\":\"type\"}"
    )

  brandNotifyConfig(brandId: String!): QueryMetaCustomerConfigResponse
    @httpOperation(
      path: "/meta/{args.brandId}/notifyConfig"
      operationSpecificHeaders: "{\"accept\":\"application/json\"}"
      httpMethod: GET
    )

  dashboard(brandId: String!): QueryDashboardResponse
    @httpOperation(
      path: "/meta/config/dashboard/{args.brandId}"
      operationSpecificHeaders: "{\"accept\":\"application/json\"}"
      httpMethod: GET
    )
}

type BrandConfigVo {
  id: BigInt
  brandId: String
  brandBaseConfigVo: BrandBaseConfigVo
  createTime: DateTime
  createBy: String
  updateTime: DateTime
  updateBy: String
}

type QueryMetaCustomerConfigResponse {
  responseCode: String
  responseMsg: String
  data: [BrandConfigVo]
}

type QueryCustomerConfigResponse {
  responseCode: String
  responseMsg: String
  data: [BrandConfigVo]
}

enum query_queryDashboard_data_allOf_0_configType {
  TAG_RULE
  COHORT_RULE
  CUSTOMER_LIST
  CUSTOMER_VIEW
  TAG_COHORT_LIST
  TAG_NOTIFY_USER
  TAG_CATEGORY_PERMISSION
  COHORT_EXPORT
  CUSTOMER_DASHBOARD
}

interface BrandBaseConfigVo @discriminator(propertyName: "configType") {
  configType: query_queryDashboard_data_allOf_0_configType
}

type CustomerDashboardConfigVo implements BrandBaseConfigVo {
  configType: query_queryDashboard_data_allOf_0_configType
  allChannelCustomerConfig: AllChannelCustomerConfig
  channelCustomerConfig: ChannelCustomerConfig
  keyCohortConfig: KeyCohortConfig
  tagConfig: TagConfig
  cohortConfig: CohortConfig
}

type QueryDashboardResponse {
  responseCode: String
  responseMsg: String
  data: CustomerDashboardConfigVo
}

Query

query Dashboard($brandId: String!) {
    brandConfig(brandId: $brandId, type: "CUSTOMER_LIST") {
        data {
            brandBaseConfigVo {
                configType
            }
            id
            brandId
        }
    }
}

Error

{
    "data": {
        "brandConfig": {
            "data": [
                {
                    "brandBaseConfigVo": null,
                    "id": 31,
                    "brandId": "122"
                }
            ]
        }
    },
    "errors": [
        {
            "message": "Abstract type \"BrandBaseConfigVo\" must resolve to an Object type at runtime for field \"BrandConfigVo.brandBaseConfigVo\". Either the \"BrandBaseConfigVo\" type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
            "path": [
                "brandConfig",
                "data",
                0,
                "brandBaseConfigVo"
            ]
        }
    ]
}

Expected behavior

I expect the query to execute without any errors and return the requested data.

Steps to reproduce(Because it involves production projects and it is not convenient to provide reproducible examples, please refer to the following steps)

  1. Generate the provided schema using GraphQL Mesh.
  2. Execute the provided query using the generated schema.
  3. Observe the error in the response.

Possible solution

As the error suggests, the abstract type "BrandBaseConfigVo" must resolve to an Object type at runtime for the field "BrandConfigVo.brandBaseConfigVo". To fix this issue, either the "BrandBaseConfigVo" type should provide a "resolveType" function, or each possible type should provide an "isTypeOf" function.

Please let me know if you need any additional information or if there is a workaround available for this issue. Thank you for your assistance.

ardatan commented 5 months ago

Sorry for the late response! But we need a full reproduction with an example OpenAPI to reproduce it on our end. If you still have the issue with the latest version, let us know so we can reopen this issue.