Skip to content

Commit 6539d5e

Browse files
[Style Guide] Merge GraphQL API Explorer info from README into Style Guide (#25116)
* graphql merge content * Small tweaks to customer variable example * Apply suggestions from code review Co-authored-by: Pedro Sousa <[email protected]> --------- Co-authored-by: Pedro Sousa <[email protected]>
1 parent 88f3c26 commit 6539d5e

File tree

1 file changed

+37
-21
lines changed
  • src/content/docs/style-guide/components

1 file changed

+37
-21
lines changed

src/content/docs/style-guide/components/code.mdx

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ export default {
113113
```
114114
````
115115

116-
## GraphQL API explorer
116+
## GraphQL API Explorer
117117

118-
If you add the `graphql-api-explorer` option to the opening code fence for a `graphql` code block, it will
119-
add a "Run in GraphQL API Explorer" link that will take the user to the [GraphQL API explorer](https://graphql.cloudflare.com/explorer).
118+
Add `graphql-api-explorer` to the opening code fence to create a `graphql` code block with a **Run in GraphQL API Explorer** button that leads to [GraphQL API Explorer](https://graphql.cloudflare.com/explorer).
120119

121-
### Live demo
120+
:::note
121+
This button only works if the person selecting it is logged in or has an API token saved.
122+
:::
122123

124+
````mdx live
123125
```graphql graphql-api-explorer title="A GraphQL query"
124126
query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) {
125127
viewer {
@@ -137,25 +139,39 @@ query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) {
137139
}
138140
}
139141
```
142+
````
140143

141-
### How to use
144+
### Variables
142145

143-
````mdx "graphql-api-explorer"
144-
```graphql graphql-api-explorer title="A GraphQL query"
145-
query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) {
146-
viewer {
147-
zones(filter: { zoneTag: $zoneTag }) {
148-
firewallEventsAdaptive(
149-
filter: { datetime_gt: $start, datetime_lt: $end }
150-
limit: 2
151-
orderBy: [datetime_DESC]
152-
) {
153-
action
154-
datetime
155-
host: clientRequestHTTPHost
156-
}
157-
}
158-
}
146+
In the GraphQL API Explorer, the **Variables** section is automatically filled based on the names and types of the variables defined in your query:
147+
- Variables that include `start` and are of type `Time` are set to six hours before the current time
148+
- Variables that include `end` and are of type `Time` are set to the current time
149+
- Variables that include `start` and are of type `Date` are set to 24 hours before the current date
150+
- Variables that include `end` and are of type `Date` are set to the current date
151+
- Variables that include `zoneTag` and are of type `string` are set to "ZONE_ID"
152+
- Variables that include `accountTag` and are of type `string` are set to "ACCOUNT_ID"
153+
- Variables that include `id` and are of type `string` are set to "REPLACE_WITH_ID"
154+
- Variables that include `limit` and are of type `int` are set to 100
155+
- Any other variable with a type of `string` is set to "REPLACE_WITH_STRING"
156+
157+
You can also add custom variables by setting their values as a JSON string in the `graphql-api-explorer` metadata. The custom variables will be merged with the automatically populated variables.
158+
159+
In the following example, the custom value is `custom-variable`:
160+
161+
````mdx
162+
```graphql graphql-api-explorer='{"uID": "custom-variable"}' title="A GraphQL query"
163+
query GraphqlExample($zoneTag: string, $start: Time, $end: Time) {
164+
viewer {
165+
zones(filter: { zoneTag: $zoneTag }) {
166+
...
167+
}
168+
}
159169
}
160170
```
161171
````
172+
173+
So, the **Variables** would look something like this:
174+
175+
```
176+
{"zoneTag":"ZONE_ID", "start":"2025-09-11T14:00:00Z", "end":"2025-09-11T20:00:00Z", "uId": "custom-variable"}
177+
```

0 commit comments

Comments
 (0)