502 response when proxying a GraphQL Endpoint that works in HTTP mode

Hello there,

I recently set up a GraphQL Endpoint (https://gontoz.escape.tech) using tyk’s cloud trial.

  • The API works, and responds properly from the playground inside tyk
  • The API works properly when proxified in HTTP mode
  • I receive a 502 error when trying the same request on the same API, but in GraphQL mode
  • No 502 when sending an empty request.

What am I doing wrong? I tried the 502 troubleshooting in tyk’s doc but it didn’t help.

Thanks in advance folks

Proxy in GraphQL mode:

Hey @glimow, welcome to the community!

Would you be able to share API definition of that service that doesn’t work for you? I can do some checking on this.

Hi agata, thanks for your answer,

Sure, here it is:

{
  "created_at": "2022-08-19T11:02:10Z",
  "api_model": {},
  "api_definition": {
    "api_id": "1e91b792d3634c414a86a833c5070f4d",
    "jwt_issued_at_validation_skew": 0,
    "upstream_certificates": {},
    "use_keyless": true,
    "enable_coprocess_auth": false,
    "base_identity_provided_by": "",
    "custom_middleware": {
      "pre": [],
      "post": [],
      "post_key_auth": [],
      "auth_check": {
        "name": "",
        "path": "",
        "require_session": false,
        "raw_body_only": false
      },
      "response": [],
      "driver": "",
      "id_extractor": {
        "extract_from": "",
        "extract_with": "",
        "extractor_config": {}
      }
    },
    "disable_quota": false,
    "custom_middleware_bundle": "",
    "cache_options": {
      "cache_timeout": 60,
      "enable_cache": true,
      "cache_all_safe_requests": false,
      "cache_response_codes": [],
      "enable_upstream_cache_control": false,
      "cache_control_ttl_header": "",
      "cache_by_headers": []
    },
    "enable_ip_blacklisting": false,
    "tag_headers": [],
    "jwt_scope_to_policy_mapping": {},
    "pinned_public_keys": {},
    "expire_analytics_after": 0,
    "domain": "",
    "openid_options": {
      "providers": [],
      "segregate_by_client": false
    },
    "jwt_policy_field_name": "",
    "enable_proxy_protocol": false,
    "jwt_default_policies": [],
    "active": true,
    "jwt_expires_at_validation_skew": 0,
    "config_data": {},
    "notifications": {
      "shared_secret": "",
      "oauth_on_keychange_url": ""
    },
    "jwt_client_base_field": "",
    "auth": {
      "use_param": false,
      "param_name": "",
      "use_cookie": false,
      "cookie_name": "",
      "auth_header_name": "Authorization",
      "use_certificate": false,
      "validate_signature": false,
      "signature": {
        "algorithm": "",
        "header": "",
        "use_param": false,
        "param_name": "",
        "secret": "",
        "allowed_clock_skew": 0,
        "error_code": 0,
        "error_message": ""
      }
    },
    "check_host_against_uptime_tests": false,
    "auth_provider": {
      "name": "",
      "storage_engine": "",
      "meta": {}
    },
    "blacklisted_ips": [],
    "graphql": {
      "schema": "\"\"\"Exposes a URL that specifies the behaviour of this scalar.\"\"\"\ndirective @specifiedBy(\n  \"\"\"The URL that specifies the behaviour of this scalar.\"\"\"\n  url: String!\n) on SCALAR\n\ntype Account {\n  id: ID\n  amount: Int\n  owner: User\n}\n\ntype AuthentificationResult {\n  success: Boolean!\n  token: String\n}\n\ntype CreditCard {\n  number: String!\n  cvv: String!\n  belong_to: User!\n}\n\ntype File {\n  id: ID!\n}\n\nscalar JSON\n\ntype Mutation {\n  resetPassword(username: String!, resetPasswordToken: String!, new_password: String!): PasswordResetSuccess!\n  newTransaction(transaction: TransactionInput!): Transaction\n  newUser(userInput: UserInput!): NewUserSuccess\n  authentification(username: String!, password: String!): AuthentificationResult!\n  uploadUserAvatar(file: Upload!): String!\n  addUserInfo(info: JSON!): User!\n}\n\ntype NewUserSuccess {\n  success: Boolean!\n  user: User\n}\n\ntype PasswordResetSuccess {\n  success: Boolean!\n  user: User\n}\n\ntype Query {\n  userTransactions(user_id: ID!): [Transaction]\n  me: User\n  debug(test: String): [User]\n  user(user_id: ID): User\n  bitcoinPrice(api_key: String): String\n  menu(menu_type: String): String\n  this_query_doesnt_exist: String\n  get_bitcoin_price(bitcoin_url: String): String\n  authorizeTransaction(authorization_code: String): String\n  printCurrencyUsed(user_id: String): String\n}\n\ntype Role {\n  name: String!\n  description: String\n}\n\ntype Transaction {\n  id: ID!\n  description: String\n  user_from: User!\n  user_to: User!\n  amount: Float!\n  media: File\n  image_resize_parameters: String\n  image: String\n}\n\ninput TransactionInput {\n  user_id_from: ID!\n  user_id_to: ID!\n  amount: Float!\n  image_resize_parameters: [Int]\n  image: String\n  description: String\n}\n\nscalar Upload\n\ntype User {\n  id: ID!\n  username: String!\n  email: String!\n  provider: String\n  password: String!\n  resetPasswordToken: String\n  confirmed: Boolean!\n  blocked: Boolean!\n  role: Role!\n  transactions_received: [Transaction]\n  transactions_emitted: [Transaction]\n  balance: Float\n  city: String\n  country: String\n  address: String\n  credit_card: CreditCard\n  iban: String\n  last_ip: String\n  job_title: String\n  secret: String\n  info: JSON\n}\n\ninput UserInput {\n  username: String!\n  email: String!\n  provider: String\n  password: String!\n  city: String\n  country: String\n  address: String\n  iban: String\n  last_ip: String\n  job_title: String\n  secret: String\n}\n",
      "enabled": true,
      "engine": {
        "field_configs": [],
        "data_sources": []
      },
      "type_field_configurations": [],
      "execution_mode": "proxyOnly",
      "proxy": {
        "auth_headers": {}
      },
      "subgraph": {
        "sdl": ""
      },
      "supergraph": {
        "subgraphs": [
          {
            "api_id": "",
            "name": "",
            "url": "",
            "sdl": "",
            "headers": {}
          }
        ],
        "merged_sdl": "",
        "global_headers": {},
        "disable_query_batching": false
      },
      "version": "2",
      "playground": {
        "enabled": false,
        "path": ""
      },
      "last_schema_update": "2022-08-19T11:02:10.36Z"
    },
    "hmac_allowed_clock_skew": -1,
    "dont_set_quota_on_create": false,
    "uptime_tests": {
      "check_list": [],
      "config": {
        "expire_utime_after": 0,
        "service_discovery": {
          "use_discovery_service": false,
          "query_endpoint": "",
          "use_nested_query": false,
          "parent_data_path": "",
          "data_path": "",
          "cache_timeout": 60
        },
        "recheck_wait": 0
      }
    },
    "enable_jwt": false,
    "do_not_track": false,
    "name": "Gontoz Escape",
    "slug": "gontoz-escape",
    "oauth_meta": {
      "allowed_access_types": [],
      "allowed_authorize_types": [],
      "auth_login_redirect": ""
    },
    "CORS": {
      "enable": false,
      "max_age": 24,
      "allow_credentials": false,
      "exposed_headers": [],
      "allowed_headers": [
        "Origin",
        "Accept",
        "Content-Type",
        "X-Requested-With",
        "Authorization"
      ],
      "options_passthrough": false,
      "debug": false,
      "allowed_origins": [
        "*"
      ],
      "allowed_methods": [
        "GET",
        "POST",
        "HEAD"
      ]
    },
    "event_handlers": {
      "events": {}
    },
    "proxy": {
      "target_url": "https://gontoz.escape.tech/graphql",
      "service_discovery": {
        "endpoint_returns_list": false,
        "cache_timeout": 0,
        "parent_data_path": "",
        "query_endpoint": "",
        "use_discovery_service": false,
        "_sd_show_port_path": false,
        "target_path": "",
        "use_target_list": false,
        "use_nested_query": false,
        "data_path": "",
        "port_data_path": ""
      },
      "check_host_against_uptime_tests": false,
      "transport": {
        "ssl_insecure_skip_verify": false,
        "ssl_min_version": 0,
        "proxy_url": "",
        "ssl_ciphers": []
      },
      "target_list": [],
      "preserve_host_header": false,
      "strip_listen_path": true,
      "enable_load_balancing": false,
      "listen_path": "/gontoz-escape/",
      "disable_strip_slash": true
    },
    "client_certificates": [],
    "use_basic_auth": false,
    "version_data": {
      "not_versioned": true,
      "default_version": "",
      "versions": {
        "Default": {
          "name": "Default",
          "expires": "",
          "paths": {
            "ignored": [],
            "white_list": [],
            "black_list": []
          },
          "use_extended_paths": true,
          "extended_paths": {
            "ignored": [],
            "white_list": [],
            "black_list": [],
            "transform": [],
            "transform_response": [],
            "transform_jq": [],
            "transform_jq_response": [],
            "transform_headers": [],
            "transform_response_headers": [],
            "hard_timeouts": [],
            "circuit_breakers": [],
            "url_rewrites": [],
            "virtual": [],
            "size_limits": [],
            "method_transforms": [],
            "track_endpoints": [],
            "do_not_track_endpoints": [],
            "validate_json": [],
            "internal": []
          },
          "global_headers": {},
          "global_headers_remove": [],
          "global_response_headers": {},
          "global_response_headers_remove": [],
          "ignore_endpoint_case": false,
          "global_size_limit": 0,
          "override_target": ""
        }
      }
    },
    "jwt_scope_claim_name": "",
    "use_standard_auth": false,
    "session_lifetime": 0,
    "hmac_allowed_algorithms": [],
    "disable_rate_limit": false,
    "definition": {
      "location": "header",
      "key": "x-api-version",
      "strip_path": false
    },
    "use_oauth2": false,
    "jwt_source": "",
    "jwt_signing_method": "",
    "jwt_not_before_validation_skew": 0,
    "use_go_plugin_auth": false,
    "jwt_identity_base_field": "",
    "allowed_ips": [],
    "request_signing": {
      "is_enabled": false,
      "secret": "",
      "key_id": "",
      "algorithm": "",
      "header_list": [],
      "certificate_id": "",
      "signature_header": ""
    },
    "org_id": "62ff6c2043d01e0001161429",
    "enable_ip_whitelisting": false,
    "global_rate_limit": {
      "rate": 0,
      "per": 0
    },
    "protocol": "",
    "enable_context_vars": false,
    "tags": [
      "aws-eu-central-1"
    ],
    "basic_auth": {
      "disable_caching": false,
      "cache_ttl": 0,
      "extract_from_body": false,
      "body_user_regexp": "",
      "body_password_regexp": ""
    },
    "listen_port": 0,
    "session_provider": {
      "name": "",
      "storage_engine": "",
      "meta": {}
    },
    "auth_configs": {
      "authToken": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      },
      "basic": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      },
      "coprocess": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      },
      "hmac": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      },
      "jwt": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      },
      "oauth": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      },
      "oidc": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization",
        "use_certificate": false,
        "validate_signature": false,
        "signature": {
          "algorithm": "",
          "header": "",
          "use_param": false,
          "param_name": "",
          "secret": "",
          "allowed_clock_skew": 0,
          "error_code": 0,
          "error_message": ""
        }
      }
    },
    "strip_auth_data": false,
    "id": "62ff6db21e7dd60001e31758",
    "certificates": [],
    "enable_signature_checking": false,
    "use_openid": false,
    "internal": false,
    "jwt_skip_kid": false,
    "enable_batch_request_support": false,
    "enable_detailed_recording": true,
    "response_processors": [],
    "use_mutual_tls_auth": false
  },
  "hook_references": [],
  "is_site": false,
  "sort_by": 0,
  "user_group_owners": [],
  "user_owners": []
}

Note that this is the default config from the setup tutorial

  • Everything Default
  • No authentication

I just switched from HTTP to GraphQL when creating the API.

Hey @glimow,

I did some checking and it looks like we have some issues with the gateway when you try to run

query {
  __typename
}

on any GraphQL API via Postman or the Playground in the gateway as well. I’ll create a ticket and ask the dev team to take a look. I’ll update you here once I know anything.

Could I ask you to do one more thing for me? I was trying to determine if I can run any other query on that GQL API you used as your upstream and I couldn’t get any to work. I’m not sure if I’m missing auth or something - the errors I get are not specific. For example this looks like it should be a legit query:

query {
  me {
    username
  }
}

but the response I get is all errors upon errors:

{
  "data": {
    "me": null
  },
  "errors": [
    {
      "message": "'NoneType' object is not iterable",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "me"
      ],
      "extensions": {
        "exception": {
          "stacktrace": [
            "Traceback (most recent call last):",
            "  File \"/root/.cache/pypoetry/virtualenvs/gontoz-9TtSrW0h-py3.10/lib/python3.10/site-packages/graphql/execution/execute.py\", line 625, in await_result",
            "    return_type, field_nodes, info, path, await result",
            "  File \"/root/.cache/pypoetry/virtualenvs/gontoz-9TtSrW0h-py3.10/lib/python3.10/site-packages/ariadne/utils.py\", line 69, in async_wrapper",
            "    return await func(*args, **convert_to_snake_case(kwargs))",
            "  File \"/app/./gontoz/queries.py\", line 43, in resolve_me",
            "    return database.get_user(info.context['user'])",
            "  File \"/app/./gontoz/database_manager/main.py\", line 324, in get_user",
            "    dict(self.cur.execute(query, query_values).fetchone()))",
            "TypeError: 'NoneType' object is not iterable"
          ],
          "context": {
            "self": "<gontoz.datab...x7f5727b804f0>",
            "user_id": "None",
            "query": "'SELECT * FRO...HERE id = (?)'",
            "query_values": "(None,)"
          }
        }
      }
    }
  ]
}

Can you double check that for other valid queries you can get the same response in GraphQL Playground and via the gateway?

Hi @agata-wit,
Thanks for your answer,

You are right, when I run the following valid query it works:

query {
 user(user_id:1) {username}
}

Even more surprising, running a full introspection query also works. So it’s really at least the

query {
  __typename
}

That is not handled by the tyk gateway.
I’m interested in getting updated if your dev team has a fix for that, in the meantime, I’ll try to find a workaround on my end.

@glimow I dropped the defect into the squad backlog. I’ll relay any updates once they come up.