@graphql-codegen/testing
Version:
GraphQL Codegen Testing Utils
88 lines (72 loc) • 2.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolversTestingValidate = exports.resolversTestingSchema = void 0;
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
const testing_1 = require("@graphql-codegen/testing");
const typescript_1 = require("@graphql-codegen/typescript");
const graphql_1 = require("graphql");
exports.resolversTestingSchema = (0, graphql_1.buildSchema)(/* GraphQL */ `
type MyType {
foo: String! @authenticated
otherType: MyOtherType
withArgs(arg: String, arg2: String!): String
unionChild: ChildUnion
}
type Child {
bar: String!
parent: MyType
}
type MyOtherType {
bar: String!
}
union ChildUnion = Child | MyOtherType
type Query {
something: MyType!
}
type Subscription {
somethingChanged: MyOtherType
}
interface Node {
id: ID!
}
type SomeNode implements Node {
id: ID!
}
interface AnotherNode {
id: ID!
}
interface WithChild {
unionChild: ChildUnion
node: AnotherNode
}
interface WithChildren {
unionChildren: [ChildUnion!]!
nodes: [AnotherNode!]!
}
type AnotherNodeWithChild implements AnotherNode & WithChild {
id: ID!
unionChild: ChildUnion
interfaceChild: Node
}
type AnotherNodeWithAll implements AnotherNode & WithChild & WithChildren {
id: ID!
unionChild: ChildUnion
unionChildren: [ChildUnion!]!
interfaceChild: Node
interfaceChildren: [Node!]!
}
union MyUnion = MyType | MyOtherType
scalar MyScalar
directive @myDirective(arg: Int!, arg2: String!, arg3: Boolean!) on FIELD
directive @authenticated on FIELD_DEFINITION
`);
const resolversTestingValidate = async (content, config = {}, pluginSchema = exports.resolversTestingSchema, additionalCode = '') => {
const mergedContent = (0, plugin_helpers_1.mergeOutputs)([
await (0, typescript_1.plugin)(pluginSchema, [], config, { outputFile: '' }),
content,
additionalCode,
]);
(0, testing_1.validateTs)(mergedContent);
return mergedContent;
};
exports.resolversTestingValidate = resolversTestingValidate;
;