GraphQL
GraphQL field resolver
GraphQL describes the shape of an API using a typed schema. A client selects fields, and resolver functions obtain their values. Unlike a fixed REST representation, the response can match the requested selection. A GraphQL engine parses, validates and executes an operation; calling a resolver directly tests application logic only. Do not concatenate untrusted input into operation strings. Never interpret a typed schema as an access policy. Do not equate resolver tests with schema validation, HTTP status or GraphQL execution. Source: https://graphql.org/learn/execution/ Local examples do not establish third-party integration support.
Formal Syntax & Structure
nodejs syntaxnodejs
resolver(parent, args, context, info)Working Example
Example Snippetnodejs
const books = [{id:'b1', title:'River Atlas', pages:120}];function book(parent, {id}, context) { return context.books.find(row => row.id === id) ?? null;}console.log(JSON.stringify(book(null,{id:'b1'},{books})));console.log(book(null,{id:'missing'},{books}));