core-types-graphql
Version:
core-types ⬌ GraphQL conversion
28 lines (27 loc) • 806 B
JavaScript
import { Kind, } from 'graphql';
export function gqlNameNode(name) {
return { kind: Kind.NAME, value: name };
}
export function gqlUnionType({ name, description, types }) {
return {
kind: Kind.UNION_TYPE_DEFINITION,
name,
...(description ? { description } : {}),
types,
};
}
export function gqlNamedTypeNode(name) {
return { kind: Kind.NAMED_TYPE, name: gqlNameNode(name) };
}
export function gqlListTypeNode(type) {
return { kind: Kind.LIST_TYPE, type };
}
export function gqlMaybeRequiredNode(type, required) {
return !required ? type : { kind: Kind.NON_NULL_TYPE, type };
}
export function gqlStripRequired(type) {
return isRequired(type) ? type.type : type;
}
export function isRequired(type) {
return type.kind === Kind.NON_NULL_TYPE;
}