The Graphcool Frameworks lets you integrate (serverless) functions with your service to react to events, execute business logic, extend your GraphQL API and hook into the operations of your CRUD API.
There generally are three kinds of functions that you can implement
To add a function to your Graphcool service, you need to add it to the service definition file under the
functions section and apply the changes using
When being added, a function needs the following information:
handler: Specifies how the function should be invoked (either as a webhook or a managed function that will be deployed by Graphcool directly)
type: Specifies which of the four available function types (
resolver) this function is.
query: Points to a file containing the subscription query (which determines the input type of the function).
operation: Specifies for which operation on which model type this function should be invoked, e.g.
schema: Defines the necessary extensions on the
Mutationtype (and potentially additional types that represent the input or return types of the new field).
handler of a function can either refer to a managed function or a webhook.
With a managed function, you don't have to worry about explicit deployment of your function since it will get deployed along with your Graphcool service when you're running
The source code for a managed function needs to be located in your service directory, typically in a folder called
Here is an example of a managed function in the service configuration file:
1 2 3 4 5
functions: hello: handler: code: src: ./src/hello.js
For conciseness, you can also refer to the file as the value for
code or directly for
handler. The following two notations are equivalent to the previous one:
1 2 3 4
functions: hello: handler: code: ./src/hello.js
1 2 3
functions: hello: handler: ./src/hello.js
A webhook needs a
url that specifies where it can be invoked. You can further specify the HTTP
headers that should be attached to the request that's sent to the webhook.
Here is an example of a function that's specified as a webhook:
1 2 3 4 5 6 7
functions: hello: handler: webhook: url: http://example.org/hello headers: Content-Type: application/json
If you don't want to specify any headers, you can simply write the configuration like so:
1 2 3 4
functions: hello: handler: webhook: http://example.org/hello
Was this page helpful?