# Containers

As previously mentioned, the Container is a thin wrapper around the controller, it defines what handles each defined GraphQL endpoint and executes the same method but at the Controller level.

This is how we tell GraphQL that a container exists and that it handles some calls

...
import { YourContainer } from './yourfeature.container';

export const Queries = {
    version: () => '2.2.0',
    // Existing Containers
    ...YourContainer.resolveQueries()
};

export const Mutations = {
    // Existing Containers
    ...YourContainer.resolveMutations()
}

These will be registered with GraphQL to make that execution link between the two. Here is the definition of the resolveQueries method to show you how it works on that end.

// customers.container.ts
// ... code

public static resolveQueries()
{
    return {
        customers: CustomerContainer.customers,
        customer: CustomerContainer.customer,
        emailUsed: CustomerContainer.emailUsed,
        //... and much more
    };
}

This defines every GraphQL endpoint we handle (object keys) and we give the container method that handles it. The established standard is to use the same name as the endpoint.

So for example, if you create an endpoint call mySuperFeature in your container you would have

return {
    mySuperFeature: YourContainer.mySuperFeature
}

Following the standard will make it very easy to find what piece of code handles a specific endpoint when debugging. If you search for controller.theEndPointYouAreLookingFor you will find it every time.

Containers only contain static methods and should normally have only 1 line of code. Something like this:

import { YourController } from "../controllers/your.controller";

export class YourContainer 
{
    private static controller = new YourController();

    public static async yourFeature(_obj, args, context) 
    {
        return YourContainer.controller.yourFeature(args, context);
    }
}
Last Updated: 7/15/2022, 3:12:37 PM