hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.09k stars 2.77k forks source link

bug: query remote schema fields cause errors `There can be only one variable named \"$hasura_json_var_1\".` #8219

Open vuongxuongminh opened 2 years ago

vuongxuongminh commented 2 years ago

Version Information

Server Version: v2.2.0

Environment

OSS

What is the expected behaviour?

Query remote schema (Hasura) fields with input variables did not cause errors

What is the current behaviour?

Query remote schema (Hasura) fields with input variables will cause errors: There can be only one variable named \"$hasura_json_var_1\".

How to reproduce the issue?

  1. Prepare environment with Docker compose file bellow:
version: '3.5'
services:
  postgres1:
    image: postgres:13-alpine
    environment:
      POSTGRES_DB: 'hasura'
      POSTGRES_PASSWORD: 'postgres'
  postgres2:
    image: postgres:13-alpine
    environment:
      POSTGRES_DB: 'hasura'
      POSTGRES_PASSWORD: 'postgres'
  hasura1:
    restart: on-failure
    image: hasura/graphql-engine:v2.2.0
    ports:
      - 8080:8080
    environment:
      HASURA_GRAPHQL_DATABASE_URL: 'postgres://postgres:postgres@postgres1/hasura'
      HASURA_GRAPHQL_ENABLE_CONSOLE: 'true'
      HASURA_GRAPHQL_DEV_MODE: 'true'
  hasura2:
    restart: on-failure
    image: hasura/graphql-engine:v2.2.0
    ports:
      - 8081:8080
    environment:
      HASURA_GRAPHQL_DATABASE_URL: 'postgres://postgres:postgres@postgres2/hasura'
      HASURA_GRAPHQL_ENABLE_CONSOLE: 'true'
      HASURA_GRAPHQL_DEV_MODE: 'true'
  1. Access Hasura 1 via url: http://localhost:8080 and add Contentful remote schema: https://graphql.contentful.com/content/v1/spaces/f8bqpb154z8p/environments/master?access_token=9d5de88248563ebc0d2ad688d0473f56fcd31c600e419d6c8962f6aed0150599

  2. Access Hasura 2 via url: http://localhost:8081 and add Hasura 1 remote schema: http://hasura1:8080/v1/graphql

  3. Modify remote schema Hasura 1 with type and fields prefix with hasura1_

  4. Execute query bellow in Hasura 2 console:

query MyQuery($where: hasura1_LessonFilter, $limit: Int) {
  hasura1_lessonCollection(where: $where, limit: $limit) {
    total
  }
}

With variables:

{
  "where": {
    "slug_contains": "a"
  },
  "limit": 1
}
vuongxuongminh commented 2 years ago

This issue still happen on version 2.5.0

av commented 2 years ago

There's a tangential issue, when GraphQL customization is in place for a Remote Schema.

Hasura doesn't seem to rename the query variables types to their original value before sending request to the remote server:

query organization_config($orderBy: [signals_organization_config_order_by!]) {
    items: signals_organization_config(
      order_by: $orderBy,
      limit: 10
    ) {
      created_at
      org_id
    }
}

Error is:

{
  "data": null,
  "errors": [
    {
      "extensions": {
        "code": "validation-failed",
        "path": "$.selectionSet.organization_config.args.order_by[0].org_id"
      },
      "message": "variable \"hasura_json_var_1\" is declared as signals_order_by, but used where order_by is expected"
    }
  ]

Where signals_organization_config is a prefixed organization_config field from a signals Remote Schema.

vuongxuongminh commented 2 years ago

@av issue solved since 2.11