hasura / hasura/graphql-engine
Allow Separate Introspection and Query Endpoints
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
Right now, I must use one URL for both introspection and other query resolution, but my source of truth for my GraphQL schema is not the server than handles non-introspection queries and mutations, it is a schema registry with its own URL. I can't use use that schema registry as the source of truth for a GraphQL schema without making the schema registry responsible for resolving GraphQL queries.
I am currently forced to make my remote schema non-introspection-query-resolving server support schema introspection in production, or otherwise set up redirect rules based on the type of query being made.
### Describe the solution you'd like
Provide additional configuration options in `remote_schemas.yaml`:
- `introspection_url` for hard-coded URLs
```yaml
- name: my-remote-schema
definition:
url_from_env: REMOTE_SCHEMA_QUERY_ENDPOINT
introspection_url: https://my-schema.registry.com/graphql
timeout_seconds: 200
forward_client_headers: true
```
- `introspection_url_from_env` for to use an environment variable for `introspection_url`
```yaml
- name: my-remote-schema
definition:
url_from_env: REMOTE_SCHEMA_QUERY_ENDPOINT
introspection_url_from_env: SCHEMA_REGISTRY_INTROSPECTION_ENDPOINT
timeout_seconds: 200
forward_client_headers: true
```
non-introspection queries could still be resolved by sending requests to `url_from_env`.
introspection would be done by sending the introspection query to `introspection_url_from_env`.
### Describe alternatives you've considered
#### Add an external polling service
Currently, I have an external polling service watching for schema registry updates.
Each time there's an update to the GQL schema in the schema registry, I send a refresh remote schema metadata request to Hasura's API.
Because introspection queries go to pod replicas which are themselves polling the schema registry for updates, there is a race condition between the remote schema pod replicas and the remote-schema-metadata-reloading polling service. We work around this by adding an explicit one minute delay between finding an update and making the reload metadata request.
Suffice to say, this is not a beginner-friendly solution.
#### Redirect traffic at the loadbalancer
The loadbalancer in front of the pod replicas could redirect traffic to the schema registry's IP for introspection queries. I haven't seen much in terms of graphql-friendly query-based-routing, but it would work.
#### Redirect traffic at the pod
The pod resolving the queries for the remote schema could redirect to the schema registry for introspection queries, but this creates unnecessary work.
Contributor guide
Research direction
Start with the remote schema configuration represented by remote_schemas.yaml and trace how query and introspection requests are routed. The work is complete when separate hard-coded or environment-based introspection endpoints can be configured, while non-introspection requests continue using the existing query endpoint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100