GraphQL literal schema with resolvers
Motivation
Inspired on code-first vs. schema-first discussions and styled-components which use template literals string to insert functions into css expressions, I decided to try out the same approach to bind resolver functions to a field of a definition type.
How to use
Install
npm install literal-schema
or
yarn add literal-schema
Example
Using Apollo Server
// (optional) Compose with graphql-tag in order to compile typeDefs to AST.const gql = const schema = gql` type Article { id: ID! title: String! isPublished: Boolean! tags: [String!]! } type User { id: ID! name: String! articles: [Article!]! } extend type Query { users(page: Number): [User]! articles(page: Number): [Article]! }` // `schema` has the shape `{ resolvers, typeDefs }` which is compatible with ApolloServer config object.const server = schema server
Confessions
This lib is experimental and I'm just having fun here, though it has 100% of test coverage and you could actually use it, this pattern is not tested in the wild, so be careful.
Contributions are very welcome :)
Lib created with Javali