Package org.mockserver.graphql
Class GraphQLExpectationGenerator
java.lang.Object
org.mockserver.graphql.GraphQLExpectationGenerator
Generates mock
Expectations from a GraphQL schema document (SDL text or an
introspection JSON result). This is the GraphQL analogue of the OpenAPI and WSDL
importers: it turns a schema into ready-to-serve mock expectations without any
hand-authored response JSON.
For each root operation type the schema defines (Query, Mutation, Subscription), one expectation is generated that:
- matches any incoming GraphQL operation of that kind (POST to the configured
GraphQL path), using
SelectionSetMatchType.AST_SUBSETmatching with an empty expected field set so every operation of the right kind matches; - carries the supplied schema on its
GraphQLBodyand has no response body, soGraphQLResponseSynthesizersynthesizes a schema-valid{"data": {...}}response from the actual query at request time.
The schema is validated up front: an unparseable schema produces an
IllegalArgumentException so the import endpoint can report a 400, mirroring the
OpenAPI and WSDL importers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerate expectations from a GraphQL schema, matching GraphQL requests on the default/graphqlpath.Generate expectations from a GraphQL schema, matching GraphQL requests on the supplied path.
-
Constructor Details
-
GraphQLExpectationGenerator
public GraphQLExpectationGenerator()
-
-
Method Details
-
generate
Generate expectations from a GraphQL schema, matching GraphQL requests on the default/graphqlpath.- Parameters:
schemaDefinition- SDL text or an introspection JSON result- Returns:
- one expectation per root operation type defined by the schema
- Throws:
IllegalArgumentException- if the schema is null, blank, or cannot be parsed
-
generate
Generate expectations from a GraphQL schema, matching GraphQL requests on the supplied path.- Parameters:
schemaDefinition- SDL text or an introspection JSON resultpath- the request path to match (defaults to/graphqlwhen blank)- Returns:
- one expectation per root operation type defined by the schema
- Throws:
IllegalArgumentException- if the schema is null, blank, or cannot be parsed
-