Reuse Fire logic in an Express endpoint
Fire core logic doesn't really depend on GraphQL.
mutator functions are actually reusable in any Express application in a few easy steps.
They are exposed by the @vulcanjs/crud/server package.
In an Express middleware:
Call
createMutator,updateMutatorordeleteMutator(check API docs for their full). You'll need to pass thecurrentUser. If there is no current user, for instance if you use a mutator in a seed script, instead use theasAdminoption and thevalidateoption.Use Mongoose to get data
You can optionnaly pass the GraphQL context to a mutator, though it should not be needed anymore:
- Optionnaly generate the
context. This is the same context that is used in GraphQL resolvers. This concept is less common outside of the GraphQL ecosystem, but still perfectly relevant. - Generate
dataSourcesas well - Then you can use a
mutatoras you would do when creating a custom resolver, and pass it thecontextanddataSources.