Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-resolver for maps in input types #11

Open
AndreaNassisi opened this issue Oct 24, 2023 · 0 comments
Open

Auto-resolver for maps in input types #11

AndreaNassisi opened this issue Oct 24, 2023 · 0 comments
Labels
enhancement New feature or request module: GraphDB GraphDB module, convert graph schema to GraphQL schema module: resolver module: Schema Validator Schema validator module, parse GraphQL schema and inference graph database directives

Comments

@AndreaNassisi
Copy link
Contributor

AndreaNassisi commented Oct 24, 2023

The utility generates or ingests a GraphQL schema, in which input types can be maps. Generating a resolver that inference a single graph query that creates or merge multiple nodes and edges at once, following the map data structure and the schema directives.

Example
The GraphQL schema has a type Person that includes a list of type Todo, and each the Todo includes a list of Comment.
A corresponed set of nested input types: PersonInput, TodoInput, and CommentInput.
The graph database connects the nodes with label person, todo, and comment with edges of type has.

type Person @alias(property: "person") {
	firstName: String
	todos: [Todo] @relationship(edgeType: "HAS", direction: OUT)
}

type Todo @alias(property: "todo") {
	name: String
	description: String
	priority: Int
	status: String
	comments: [Comment] @relationship(edgeType: "HAS", direction: OUT)
}

type Comment @alias(property: "comment") {
	content: String
}


input PersonInput {
	firstName: String
	todos: [TodoInput]
}

input TodoInput {
	name: String
	description: String
	priority: Int
	status: String
	comments: [CommentInput]
}

input CommentInput {
	content: String
}


type Mutation {
	createNodePerson(input: PersonInput!, merge: [String]): Person
}

type Query {
	# Create Poster
	getNodePerson(filter: PersonInput): Person
	# Create Todo
	getNodeTodo(filter: TodoInput): Todo
}

schema {
	query: Query
	mutation: Mutation
}

The mutation createNodePerson accept as input a map, validated by the nested input types of the schema, like:

mutation MyMutation {
  createNodePerson( input: {
    firstName: "John", 
    todos: [
      { 
        name: "code", 
        comments: [
          {content: "I like it"},
          {content: "Will do more"}
        ]
      },
      { 
        name: "FAQ",
        comments: [
          {content: "I like it too"},
          {content: "just when I need it"}
        ]
      }
    ]}) 
  {
    firstName
  }
}

The resolver will parse the input and based of the schema will create a single openCypher query that creates the nodes and the edges at once.

The option merge toggle if a node type in the map is always created or merged, meaning finding and connecting an existing node. The merge option is a list like ["todos", "todos.comments"].

@AndreaNassisi AndreaNassisi added enhancement New feature or request module: GraphDB GraphDB module, convert graph schema to GraphQL schema module: Schema Validator Schema validator module, parse GraphQL schema and inference graph database directives module: resolver labels Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module: GraphDB GraphDB module, convert graph schema to GraphQL schema module: resolver module: Schema Validator Schema validator module, parse GraphQL schema and inference graph database directives
Projects
None yet
Development

No branches or pull requests

1 participant