Domain configuration
More
Custom queries & mutations

Custom Queries & Mutations

You can add queries and mutations to the GraphQL schema that do not result from an Entity or Operation. As you see the configuration type for Query and Mutation is the same. You should consider add behavior as Query or Mutation depending on whether you change any data or not.

QueryMutationConfig

ConfigTypeDescription
typestring | Type definitionthis can be a type name of the schema or a type definition
args{[name:string]:string | QueryMutationArgConfig }this can be a type name of the schema or a QueryMutationArgConfig
resolve(root:any, args:any, context:ResolverContext, info:any ) => anystandard resolve implementation; implement any business logic here
descriptionstringDescription that will be part of the Schema documentation

Example

In this example we define a Query "greeting" that defines one param "name" and returns a greeting using that "name" and the current time from the Runtime. As you might see we make use of the now callback, to control the "current" time, rather than relying on Date.now

import { DomainConfiguration } from "activeql-foundation";
 
export const domainConfiguration: DomainConfiguration = {
  now: () => new Date( Date.parse('2023-12-12 05:50:00') ),
  query: {
    Greeting: {
      type: "String",
      args: { name: 'String!' },
      resolve: (root:any, {name}, {runtime} ) => {
        if( runtime.now().getHours() < 6 ) {
          return `That's an early morning, ${name}`;
        }
        return `Hey ${name}, have a great day`
      }
    }
  }
}