Automatic schema generation
Gloo Gateway can automatically discover API specifications and create GraphQL schemas for gRPC and REST OpenAPI upsteams, as well as GraphQL servers.
- gRPC and REST OpenAPI upsteams: The generated
GraphQLApi
includes the configuration for resolvers and schema definitions for the types of data to return to GraphQL queries. In this case, Gloo Gateway uses local execution, which means the Envoy server executes GraphQL queries locally before it proxies them to the upstreams that provide the data requested in the queries. - GraphQL server upstreams (1.14.0 and later only): When you have a GraphQL server upstream that includes its own resolvers, the generated
GraphQLApi
includes only the schema definitions for the types of data to return to GraphQL queries. In this case, Gloo Gateway uses remote execution, which means that Envoy proxies the requests to the GraphQL server without executing the request first, and the GraphQL upstream both executes the query and provides the requested data. Additionally, Envoy validates the schema of the GraphQL server.
Automatic schema generation is recommended for use in development environments to quickly create initial GraphQLApi custom resources from existing APIs. Once these custom resources are generated, you must manage them in the same way as other Gloo custom resources, especially when deploying them into downstream environments. It is not recommended to use autogeneration in production.
Gloo Gateway supports two modes of discovery: allowlist and blocklist. For more information about these discovery modes, see the Function Discovery Service (FDS) guide.
GraphQL discovery supports only OpenAPI v3.
GraphQL discovery can be disabled entirely in the Settings
resource.
kubectl patch settings -n gloo-system default --type=merge --patch '{"spec":{"discovery":{"fdsOptions":{"graphqlEnabled":"false"}}}}'
Allowlist mode
In allowlist mode, discovery is enabled manually for only specific services by labeling those services with the function_discovery=enabled
label. This mode gives you full manual control over which services you want to expose as GraphQL services.
-
Label services for discovery.
kubectl label service <service_name> discovery.solo.io/function_discovery=enabled
-
Allow automatic generation of GraphQL schemas by enabling FDS discovery in allowlist mode.
kubectl patch settings -n gloo-system default --type=merge --patch '{"spec":{"discovery":{"fdsMode":"WHITELIST"}}}'
Blocklist mode
In blocklist mode, discovery is enabled for all supported services, unless you explicitly disable discovery for a service by using the function_discovery=disbled
label.
-
Label services that you do not want to be discovered.
kubectl label service <service_name> discovery.solo.io/function_discovery=disabled
-
Allow automatic generation of GraphQL schemas by enabling FDS discovery in blocklist mode.
kubectl patch settings -n gloo-system default --type=merge --patch '{"spec":{"discovery":{"fdsMode":"BLACKLIST"}}}'
Verifying automatic schema generation
You can verify that OpenAPI specification discovery is enabled by viewing the GraphQL custom resource that was automatically generated for your service.
kubectl get graphqlapis -n gloo-system
kubectl get graphqlapis <api_name> -o yaml -n gloo-system
For more information about the contents of the generated GraphQL schema, see the schema configuration documentation.