Resolvers

Overview

code.store platform support file based resolvers. To avoid manual file creation allowed a command cs generate:resolver, which generate an empty resolver for your query or mutation which specified in schema.graphql file in src directory.

To generate resolver execute cs generate:resolver CLI command, select resolver type: mutation or query and and specify a name:

> cs generate:resolver

? Select the type of resolver (Use arrow keys)
❯ query 
  mutation  
  
? Enter the name of your resolver hello

Also, you can use flags:

-t resolver type, one of: 'query' or 'mutation'

-n resolver name

-f force overwrite file if it already exists

For example, here a command from previous example: cs generate:resolver -t query -n hello

After command execution will be generated file get.hello.ts in src/rest directory:

/**
 * This resolver was generated by code.store CLI.
 *
 * Visit our documentation to learn more about writing custom resolvers for your GraphQL schema:
 * https://docs.code.store/getting-started/quick-start/quick-start-with-cli
 *
 * You can also join our community at https://spectrum.chat/code-store if you have any
 * questions which are not covered by the documentation.
 *
 */
import { Resolver } from 'codestore-utils';

const resolver: Resolver = async (parent, args, context, info) => {
  // Your code goes here.
  // Example of how to initialize an Entity:
  //   const exampleEntity = context.db.connection.getRepository(exampleEntity);
  //   exampleEntity.find();
  return 'Hello, World!';
}

export default resolver;

More information about resolver method and his params can be found in GraphQL section.

Last updated