- Notifications
You must be signed in to change notification settings - Fork3
License
eBay/GraphQL2JSONSchema
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Java library for converting GraphQL Schema to JSON Schema.
To enable GraphQL schema for contract verification testing we need a way to leverage GraphQL schemas with the JSON schema validator used in many validation tools. This library provides that translation capability.
The specs versioned supported by this library are:
GraphQL October 2021
JSON Schema Draft v4 to match theJSON Schema Validator
This library assumes that the GraphQL schema is valid and compliant with the spec version defined in theSpec Compliance section above. Closing curly braces}
are expected on their own line.
The GraphQL2JSONSchema library contains a parser and a transformer. The first step is to parse your GraphQL schema.
GraphQLParsergraphQLParser =newGraphQLParser();GraphQLSchemagraphQLSchema =graphQLParser.parseGraphQL(newFile("path/to/your/schema");
The second step is to convert the parsed GraphQL schema into JSON schema. The parsed GraphQL schema contains all of the defined query, mutation and subscription APIs. You MUST specify which GraphQL API you wish to transform by the operation type (OperationType
[QUERY, MUTATION, SUBSCRIPTION]) and operation name (String
). The operation name MUST be the full operation name as defined in the schema (EG:getUserById(id: string): UserDetail
).
GraphQLToJsonSchemaconverter =newGraphQLToJsonSchema(graphQLSchema);JsonNoderootNode =null;switch(operationType) {caseQUERY:rootNode =converter.convertQuery(operationName);break;caseMUTATION:rootNode =converter.convertMutation(operationName);break;caseSUBSCRIPTION:rootNode =converter.convertSubscription(operationName);break;}
- Custom scalar types are evaluated as strings.
- Object, interface, union, enum and scalar extensions are not currently supported.
- Interface definitions are not currently supported, because, all interface fields are redefined on the object that implements the interfaces.
- Custom type definitions mapped into the schema for Query, Mutation and Subscription are NOT currently supported (IE: type Query, type Mutation and type Subscription are expected to be upheld in the definition).
- Response validation assumes the response payload has been extracted from the 'data' field at the root of the response model.