|
| 1 | +--- |
| 2 | +title: GraphQL |
| 3 | +--- |
| 4 | + |
| 5 | +import { TypeTable } from 'fumadocs-ui/components/type-table'; |
| 6 | + |
| 7 | +## GraphqlConfig |
| 8 | + |
| 9 | +<TypeTable |
| 10 | + type={{ |
| 11 | + baseUrl: { |
| 12 | + description: 'The base URL', |
| 13 | + type: '`/${string}`' |
| 14 | + }, |
| 15 | + configs: { |
| 16 | + description: 'Array of GraphQL request configurations', |
| 17 | + type: 'GraphQLRequestConfig[]', |
| 18 | + typeDescriptionLink: '#GraphQLRequestConfig', |
| 19 | + required: true |
| 20 | + }, |
| 21 | + interceptors: { |
| 22 | + description: 'Optional interceptors applied to GraphQL handlers', |
| 23 | + type: "Interceptors<'graphql'>", |
| 24 | + typeDescriptionLink: './Interceptors' |
| 25 | + } |
| 26 | + }} |
| 27 | +/> |
| 28 | + |
| 29 | +<a id='GraphQLRequestConfig'></a> |
| 30 | +## GraphQLRequestConfig |
| 31 | + |
| 32 | +<TypeTable |
| 33 | + type={{ |
| 34 | + operationType: { |
| 35 | + description: 'Operation type (query or mutation)', |
| 36 | + type: 'GraphQLOperationType', |
| 37 | + typeDescriptionLink: '#GraphQLOperationType', |
| 38 | + required: true |
| 39 | + }, |
| 40 | + operationName: { |
| 41 | + description: 'Operation name (string or RegExp) used to match requests', |
| 42 | + type: 'GraphQLOperationName', |
| 43 | + typeDescriptionLink: '#GraphQLOperationName' |
| 44 | + }, |
| 45 | + query: { |
| 46 | + description: 'GraphQL query string to match against incoming requests', |
| 47 | + type: 'string' |
| 48 | + }, |
| 49 | + routes: { |
| 50 | + description: 'One or more route responses or queues for this operation', |
| 51 | + type: 'GraphQLRouteConfig[]', |
| 52 | + typeDescriptionLink: '#GraphQLRouteConfig', |
| 53 | + required: true |
| 54 | + }, |
| 55 | + interceptors: { |
| 56 | + description: 'Optional interceptors for this specific GraphQL config', |
| 57 | + type: "Interceptors<'graphql'>", |
| 58 | + typeDescriptionLink: './Interceptors' |
| 59 | + } |
| 60 | + }} |
| 61 | +/> |
| 62 | + |
| 63 | +<a id='GraphQLRouteConfig'></a> |
| 64 | +## GraphQLRouteConfig |
| 65 | + |
| 66 | +There are 2 ways to specify a GraphQL route: |
| 67 | + |
| 68 | +You can pass a `queue` field with an array of timed responses (for polling/queues): |
| 69 | + |
| 70 | +<TypeTable |
| 71 | + type={{ |
| 72 | + settings: { |
| 73 | + description: 'Optional response settings (delay, polling, status)', |
| 74 | + type: 'GraphQLSettings & { polling: true }', |
| 75 | + typeDescriptionLink: '#GraphQLSettings' |
| 76 | + }, |
| 77 | + queue: { |
| 78 | + description: 'Sequence of timed responses (for polling/queues)', |
| 79 | + type: 'Array<{ time?: number; data: GraphqlDataResponse }>', |
| 80 | + required: true |
| 81 | + }, |
| 82 | + entities: { |
| 83 | + description: 'Optional request entities mapping (cookies, headers, query, variables)', |
| 84 | + type: 'GraphQLEntitiesByEntityName', |
| 85 | + typeDescriptionLink: '#GraphQLEntitiesByEntityName' |
| 86 | + }, |
| 87 | + interceptors: { |
| 88 | + description: 'Optional interceptors applied to GraphQL routes', |
| 89 | + type: "Interceptors<'graphql'>", |
| 90 | + typeDescriptionLink: './Interceptors' |
| 91 | + } |
| 92 | + }} |
| 93 | +/> |
| 94 | + |
| 95 | +Or you can specify a single response with the `data` field: |
| 96 | + |
| 97 | +<TypeTable |
| 98 | + type={{ |
| 99 | + settings: { |
| 100 | + description: 'Optional response settings (delay, polling, status)', |
| 101 | + type: 'GraphQLSettings & { polling?: false }', |
| 102 | + typeDescriptionLink: '#GraphQLSettings' |
| 103 | + }, |
| 104 | + data: { |
| 105 | + description: 'Static or dynamic response data (function or value)', |
| 106 | + type: 'GraphqlDataResponse', |
| 107 | + typeDescriptionLink: '#GraphqlDataResponse', |
| 108 | + required: true |
| 109 | + }, |
| 110 | + entities: { |
| 111 | + description: 'Optional request entities mapping (cookies, headers, query, variables)', |
| 112 | + type: 'GraphQLEntitiesByEntityName', |
| 113 | + typeDescriptionLink: '#GraphQLEntitiesByEntityName' |
| 114 | + }, |
| 115 | + interceptors: { |
| 116 | + description: 'Optional interceptors applied to GraphQL routes', |
| 117 | + type: "Interceptors<'graphql'>", |
| 118 | + typeDescriptionLink: './Interceptors' |
| 119 | + } |
| 120 | + }} |
| 121 | +/> |
| 122 | + |
| 123 | +<a id='GraphqlDataResponse'></a> |
| 124 | +## GraphqlDataResponse |
| 125 | + |
| 126 | +<TypeTable |
| 127 | + type={{ |
| 128 | + GraphqlDataResponse: { |
| 129 | + description: 'Either a static Data value or a function producing Data (sync or async)', |
| 130 | + type: 'Data | (request: Request, entities: GraphQLEntitiesByEntityName) => Data | Promise<Data>' |
| 131 | + } |
| 132 | + }} |
| 133 | +/> |
| 134 | + |
| 135 | +<a id='GraphQLSettings'></a> |
| 136 | +## GraphQLSettings |
| 137 | + |
| 138 | +<TypeTable |
| 139 | + type={{ |
| 140 | + delay: { |
| 141 | + description: 'Optional artificial delay (ms) applied to this response', |
| 142 | + type: 'number' |
| 143 | + }, |
| 144 | + polling: { |
| 145 | + description: 'Whether this route is polling (returns queued responses)', |
| 146 | + type: 'boolean' |
| 147 | + }, |
| 148 | + status: { |
| 149 | + description: 'Optional HTTP status code for the response', |
| 150 | + type: 'number' |
| 151 | + } |
| 152 | + }} |
| 153 | +/> |
| 154 | + |
| 155 | +<a id='GraphQLOperationType'></a> |
| 156 | +## GraphQLOperationType |
| 157 | + |
| 158 | +Operation types supported by GraphQL configs |
| 159 | + |
| 160 | +```typescript |
| 161 | +type GraphQLOperationType = 'mutation' | 'query'; |
| 162 | +``` |
| 163 | + |
| 164 | +<a id='GraphQLOperationName'></a> |
| 165 | +## GraphQLOperationName |
| 166 | + |
| 167 | +Operation name |
| 168 | + |
| 169 | +```typescript |
| 170 | +type GraphQLOperationName = string | RegExp; |
| 171 | +``` |
| 172 | + |
| 173 | +<a id='GraphQLEntitiesByEntityName'></a> |
| 174 | +## GraphQLEntitiesByEntityName |
| 175 | + |
| 176 | +```typescript |
| 177 | +Record<'cookies' | 'headers' | 'query' | 'variables', GraphQLEntity>; |
| 178 | +``` |
0 commit comments