File-based Operations is a pattern we've adopted from NextJS. There are many ways to define the Operations of an API. We've decided to choose a simple approach that developers are familiar with.
The rules are simple:
- Operations must be defined in the folder
.graphqlfile becomes an API endpoint.
- Each file should contain exactly one GraphQL Query, Mutation or Subscription.
- Operations can be annotated with
@directivesto adjust their behaviour.
- The file name in front of
.graphqldefines the name of the Operation:
That's it, a simple set of constraints that lets you build API Endpoints by writing GraphQL Operations. If you're interested, read more on how we create the API Endpoints using the GraphQL to JSON RPC compiler.