Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1--- 2title: '@urql/exchange-execute' 3order: 6 4--- 5 6# Execute Exchange 7 8> **Note:** These API docs are deprecated as we now keep TSDocs in all published packages. 9> You can view TSDocs while using these packages in your editor, as long as it supports the 10> TypeScript Language Server. 11> We're planning to replace these API docs with a separate web app soon. 12 13The `@urql/exchange-execute` package contains an addon `executeExchange` for `urql` that may be used to 14execute queries against a local schema. It is therefore a drop-in replacement for the default 15_fetchExchange_ and useful for the server-side, debugging, or testing. 16 17## Installation and Setup 18 19First install `@urql/exchange-execute` alongside `urql`: 20 21```sh 22yarn add @urql/exchange-execute 23# or 24npm install --save @urql/exchange-execute 25``` 26 27You'll then need to add the `executeExchange`, exposed by this package, to your `Client`. 28It'll typically replace the `fetchExchange` or similar exchanges and must be used last if possible, 29since it'll handle operations and return results. 30 31```js 32import { createClient, cacheExchange } from 'urql'; 33import { executeExchange } from '@urql/exchange-execute'; 34 35const client = createClient({ 36 url: 'http://localhost:3000/graphql', 37 exchanges: [ 38 cacheExchange, 39 executeExchange({ 40 /* config */ 41 }), 42 ], 43}); 44``` 45 46The `executeExchange` accepts an object of options, which are all similar to the arguments that 47`graphql/execution/execute` accepts. Typically you'd pass it the `schema` option, some resolvers 48if your schema isn't already executable as `fieldResolver` / `typeResolver` / `rootValue`, 49and a `context` value or function. 50 51## Options 52 53| Option | Description | 54| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | 55| `schema` | This is of type `GraphQLSchema` and accepts either a schema that is or isn't executable. This field is _required_ while all other fields are _optional_. | 56| `rootValue` | The root value that `graphql`'s `execute` will use when starting to execute the schema. | 57| `fieldResolver` | A given field resolver function. Creating an executable schema may be easier than providing this, but this resolver will be passed on to `execute` as expected. | 58| `typeResolver` | A given type resolver function. Creating an executable schema may be easier than providing this, but this resolver will be passed on to `execute` as expected. | 59| `context` | This may either be a function that receives an [`Operation`](./core.md#operation) and returns the context value, or just a plain context value. Similarly to a GraphQL server this is useful as all resolvers will have access to your `context` |