1.0.2 • Published 5 years ago
@kaviar/loader v1.0.2
This function is for loading your GraphQL API seamlessly from multiple places (folders, files, npm packages, etc) so you can have them merged when you start your server. The basic scenario here is that you would have a startup file which loads all your modules which use a defined loader
. And after that you import the file which starts the server and uses your loader
to get the schema.
Install
npm install --save @kaviar/loader
Usage
import { Loader } from "@kaviar/loader";
const loader = new Loader();
loader.load({
// Can also be array of strings
typeDefs: `
type Query {
sayHello: String
}
`,
// Can also be array of resolvers
resolvers: {
Query: {
sayHello: () => "Hello world!",
},
},
// Can also be array of objects
schemaDirectives: {
name: MyDirective,
},
// Can be array of functions, we recommend to name your functions:
contextReducers: async function processNewVariables(context) {
return {
...context,
newVariable: "newValue",
};
},
});
Getting it all together
This would happen when you want to instantiate your server
const {
typeDefs,
resolvers,
schemaDirectives,
contextReducers,
} = loader.getSchema();