LogoLogo
CS CONSOLECOMMUNITYDOCS
  • What is code.store?
  • Our vision
  • How it works?
  • Getting started
    • Quick Start
      • Core concepts
      • Quick Start with CLI
      • Quick Start with Web Interface
    • FUNDAMENTALS
      • Services
        • GraphQL
        • REST
        • Configuration
        • Environment Variables
      • Environments
      • Projects
      • Versioning
      • Access and Authorization
      • Secret management
      • Data management
        • Import and Export
      • Generation
        • Models
        • Handlers
        • Resolvers
        • REST
        • Middlewares
      • Logging
      • Microservices
        • Communication
    • RECIPES
      • TypeScript
        • Custom .tslint
      • Basic authentication
      • Setup a local database with your service
      • GraphQL
    • Tutorials
      • Auth0 authentication
      • Metabase integration
      • Database manipulations
        • External database: MongoDB
        • External database: DynamoDB
      • Wrapping an NPM package with GraphQL: a chess server
    • FAQ
  • Command Line Interface
    • Getting started
    • Commands
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Getting started
  2. FUNDAMENTALS
  3. Generation

Resolvers

PreviousHandlersNextREST

Last updated 4 years ago

Was this helpful?

Overview

code.store platform support . 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 section.

file based resolvers
GraphQL