@omnigraph/json-schema
Version:
This package generates GraphQL Schema from JSON Schema and sample JSON request and responses. You can define your root field endpoints like below in your GraphQL Config for example;
273 lines (272 loc) • 8.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransportDirective = exports.ExampleDirective = exports.OneOfDirective = exports.EnumDirective = exports.StatusCodeTypeNameDirective = exports.FlattenDirective = exports.DictionaryDirective = exports.LinkResolverDirective = exports.LinkDirective = exports.ResponseMetadataDirective = exports.HTTPOperationDirective = exports.TypeScriptDirective = exports.PubSubOperationDirective = exports.RegExpDirective = exports.ResolveRootFieldDirective = exports.ResolveRootDirective = exports.DiscriminatorDirective = exports.LengthDirective = void 0;
const graphql_1 = require("graphql");
const transport_common_1 = require("@graphql-mesh/transport-common");
exports.LengthDirective = new graphql_1.GraphQLDirective({
name: 'length',
locations: [graphql_1.DirectiveLocation.SCALAR],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
min: {
type: graphql_1.GraphQLInt,
},
max: {
type: graphql_1.GraphQLInt,
},
},
});
exports.DiscriminatorDirective = new graphql_1.GraphQLDirective({
name: 'discriminator',
locations: [graphql_1.DirectiveLocation.INTERFACE, graphql_1.DirectiveLocation.UNION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
field: {
type: graphql_1.GraphQLString,
},
mapping: {
type: transport_common_1.ObjMapScalar,
},
},
});
exports.ResolveRootDirective = new graphql_1.GraphQLDirective({
name: 'resolveRoot',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
},
});
exports.ResolveRootFieldDirective = new graphql_1.GraphQLDirective({
name: 'resolveRootField',
locations: [
graphql_1.DirectiveLocation.FIELD_DEFINITION,
graphql_1.DirectiveLocation.ARGUMENT_DEFINITION,
graphql_1.DirectiveLocation.INPUT_FIELD_DEFINITION,
],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
field: {
type: graphql_1.GraphQLString,
},
},
});
exports.RegExpDirective = new graphql_1.GraphQLDirective({
name: 'regexp',
locations: [graphql_1.DirectiveLocation.SCALAR],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
pattern: {
type: graphql_1.GraphQLString,
},
},
});
exports.PubSubOperationDirective = new graphql_1.GraphQLDirective({
name: 'pubsubOperation',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
pubsubTopic: {
type: graphql_1.GraphQLString,
},
},
});
exports.TypeScriptDirective = new graphql_1.GraphQLDirective({
name: 'typescript',
locations: [graphql_1.DirectiveLocation.SCALAR, graphql_1.DirectiveLocation.ENUM],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
type: {
type: graphql_1.GraphQLString,
},
},
});
exports.HTTPOperationDirective = new graphql_1.GraphQLDirective({
name: 'httpOperation',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
path: {
type: graphql_1.GraphQLString,
},
operationSpecificHeaders: {
type: transport_common_1.ObjMapScalar,
},
httpMethod: {
type: new graphql_1.GraphQLEnumType({
name: 'HTTPMethod',
values: {
GET: { value: 'GET' },
HEAD: { value: 'HEAD' },
POST: { value: 'POST' },
PUT: { value: 'PUT' },
DELETE: { value: 'DELETE' },
CONNECT: { value: 'CONNECT' },
OPTIONS: { value: 'OPTIONS' },
TRACE: { value: 'TRACE' },
PATCH: { value: 'PATCH' },
},
}),
},
isBinary: {
type: graphql_1.GraphQLBoolean,
},
requestBaseBody: {
type: transport_common_1.ObjMapScalar,
},
queryParamArgMap: {
type: transport_common_1.ObjMapScalar,
},
queryStringOptionsByParam: {
type: transport_common_1.ObjMapScalar,
},
jsonApiFields: {
type: graphql_1.GraphQLBoolean,
},
},
});
exports.ResponseMetadataDirective = new graphql_1.GraphQLDirective({
name: 'responseMetadata',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
},
});
exports.LinkDirective = new graphql_1.GraphQLDirective({
name: 'link',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
defaultRootType: {
type: graphql_1.GraphQLString,
},
defaultField: {
type: graphql_1.GraphQLString,
},
},
});
exports.LinkResolverDirective = new graphql_1.GraphQLDirective({
name: 'linkResolver',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
linkResolverMap: {
type: transport_common_1.ObjMapScalar,
},
},
});
exports.DictionaryDirective = new graphql_1.GraphQLDirective({
name: 'dictionary',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
},
});
exports.FlattenDirective = new graphql_1.GraphQLDirective({
name: 'flatten',
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
},
});
exports.StatusCodeTypeNameDirective = new graphql_1.GraphQLDirective({
name: 'statusCodeTypeName',
locations: [graphql_1.DirectiveLocation.UNION],
isRepeatable: true,
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
typeName: {
type: graphql_1.GraphQLString,
},
statusCode: {
type: graphql_1.GraphQLID,
},
},
});
exports.EnumDirective = new graphql_1.GraphQLDirective({
name: 'enum',
locations: [graphql_1.DirectiveLocation.ENUM_VALUE],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
value: {
type: graphql_1.GraphQLString,
},
},
});
exports.OneOfDirective = new graphql_1.GraphQLDirective({
name: 'oneOf',
locations: [
graphql_1.DirectiveLocation.OBJECT,
graphql_1.DirectiveLocation.INTERFACE,
graphql_1.DirectiveLocation.INPUT_OBJECT,
],
});
exports.ExampleDirective = new graphql_1.GraphQLDirective({
name: 'example',
locations: [
graphql_1.DirectiveLocation.FIELD_DEFINITION,
graphql_1.DirectiveLocation.OBJECT,
graphql_1.DirectiveLocation.INPUT_OBJECT,
graphql_1.DirectiveLocation.ENUM,
graphql_1.DirectiveLocation.SCALAR,
],
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
value: {
type: transport_common_1.ObjMapScalar,
},
},
isRepeatable: true,
});
exports.TransportDirective = new graphql_1.GraphQLDirective({
name: 'transport',
args: {
subgraph: {
type: graphql_1.GraphQLString,
},
kind: {
type: graphql_1.GraphQLString,
},
location: {
type: graphql_1.GraphQLString,
},
headers: {
type: transport_common_1.ObjMapScalar,
},
queryStringOptions: {
type: transport_common_1.ObjMapScalar,
},
queryParams: {
type: transport_common_1.ObjMapScalar,
},
},
locations: [graphql_1.DirectiveLocation.OBJECT],
});