Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { TypeDefinition, TypeSystemDefinition } from 'graphql-zeus';
import { EditorNodeDefinition } from '../../Models';
import { Utils } from './Utils';
export const FieldInstance: Partial & Pick = {
options: Utils.ArrayNonNullOptions,
data: {
type: TypeSystemDefinition.FieldDefinition,
for: [TypeDefinition.InterfaceTypeDefinition, TypeDefinition.ObjectTypeDefinition],
},
acceptsInputs: (d, defs) =>
Utils.displayAsCategories(Utils.sortByParentType(Utils.dataForTypes(defs, [TypeSystemDefinition.FieldDefinition]))),
node: {
...Utils.createOND(),
outputs: [],
},
instances: undefined,
};
type: Helpers.Comment,
root: true,
data: {
type: Helpers.Comment,
},
help: help.implements,
};
const implementsObject: EditorNodeDefinition = {
node: {
notEditable: true,
name: undefined,
},
type: Helpers.Implements,
data: {
type: Helpers.Implements,
for: [TypeDefinition.ObjectTypeDefinition],
},
acceptsInputs: (d, defs) =>
Utils.dataForTypes(defs, [Helpers.Implements]).map(Utils.nodeDefinitionToAcceptedEditorNodeDefinition),
help: help.implements,
};
const directivesObject: EditorNodeDefinition = {
node: {
notEditable: true,
name: undefined,
},
type: Helpers.Directives,
data: {
type: Helpers.Directives,
for: [
TypeSystemDefinition.FieldDefinition,
TypeDefinition.ObjectTypeDefinition,
static ObjectTypeDefinition = () =>
generateTypeDefinition({
help: help.type,
type: TypeDefinitionDisplayMap[TypeDefinition.ObjectTypeDefinition],
dataType: TypeDefinition.ObjectTypeDefinition,
options: Utils.rootOptions,
acceptsInputs: (d, defs, _) =>
Utils.displayAsCategories(
Utils.sortByParentType(Utils.dataForTypes(defs, [TypeDefinition.ObjectTypeDefinition])),
),
instances: [
{
...FieldInstance,
},
{
...FieldInstance,
data: {
type: TypeSystemDefinition.UnionMemberDefinition,
for: [TypeDefinition.UnionTypeDefinition],
},
},
static ObjectTypeDefinition = () =>
generateTypeDefinition({
help: help.type,
type: TypeDefinitionDisplayMap[TypeDefinition.ObjectTypeDefinition],
dataType: TypeDefinition.ObjectTypeDefinition,
options: Utils.rootOptions,
acceptsInputs: (d, defs, _) =>
Utils.displayAsCategories(
Utils.sortByParentType(Utils.dataForTypes(defs, [TypeDefinition.ObjectTypeDefinition])),
),
instances: [
{
...FieldInstance,
},
{
...FieldInstance,
data: {
type: TypeSystemDefinition.UnionMemberDefinition,
for: [TypeDefinition.UnionTypeDefinition],
},
static resolveTree(tree: ParserTree) {
const { nodes } = tree;
const fakeResolvers = [
TypeDefinition.ObjectTypeDefinition,
TypeDefinition.InterfaceTypeDefinition,
TypeDefinition.InputObjectTypeDefinition
].reduce((a, b) => {
a = {
...a,
...arrayToDict(nodes.filter((n) => n.type.name === b).map(generateFakerResolverType))
};
return a;
}, {});
const fakeEnumResolvers = [TypeDefinition.EnumTypeDefinition].reduce((a, b) => {
a = {
...a,
...arrayToDict(nodes.filter((n) => n.type.name === b).map(generateFakerResolverEnum))
};
return a;
acceptsInputs: (d, defs, _) =>
Utils.displayAsCategories(
Utils.sortByParentType(Utils.dataForTypes(defs, [TypeDefinition.ObjectTypeDefinition])),
),
instances: [