Skip to content

Commit a0bafde

Browse files
Copilotpelikhan
andcommitted
Update GraphQL examples to remove hardcoded owner/name variables
- Remove owner/name parameters from GraphQL examples per feedback - Use viewer query for simpler first example - Use search API with label filtering for complex example - Examples now use more realistic variable parameters Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 5b0bd7c commit a0bafde

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

docs/src/content/docs/reference/scripts/github.mdx

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -221,62 +221,51 @@ console.log(releases)
221221
Execute GraphQL queries against the GitHub API using the `graphql` method. This provides access to GitHub's full GraphQL API v4, which often allows more efficient data retrieval than REST APIs.
222222

223223
```js
224-
// Basic repository information
224+
// Get current user information
225225
const query = `
226-
query($owner: String!, $name: String!) {
227-
repository(owner: $owner, name: $name) {
226+
query {
227+
viewer {
228+
login
228229
name
229-
description
230-
stargazerCount
231-
forkCount
232-
primaryLanguage {
233-
name
234-
color
235-
}
230+
email
236231
}
237232
}
238233
`
239234

240-
const result = await github.graphql(query, {
241-
owner: "microsoft",
242-
name: "genaiscript"
243-
})
235+
const result = await github.graphql(query)
244236

245-
console.log(result.repository)
237+
console.log(result.viewer)
246238
```
247239

248240
You can also query multiple data points in a single request:
249241

250242
```js
251-
// Get issues and pull requests together
243+
// Get issues with label filtering
252244
const complexQuery = `
253-
query($owner: String!, $name: String!) {
254-
repository(owner: $owner, name: $name) {
255-
issues(first: 5, states: OPEN) {
256-
nodes {
257-
number
258-
title
259-
author { login }
260-
}
261-
}
262-
pullRequests(first: 5, states: OPEN) {
263-
nodes {
245+
query($label: String!, $count: Int!) {
246+
search(query: $label, type: ISSUE, first: $count) {
247+
nodes {
248+
... on Issue {
264249
number
265250
title
251+
state
266252
author { login }
253+
repository {
254+
name
255+
owner { login }
256+
}
267257
}
268258
}
269259
}
270260
}
271261
`
272262

273263
const data = await github.graphql(complexQuery, {
274-
owner: "microsoft",
275-
name: "genaiscript"
264+
label: "label:bug state:open",
265+
count: 5
276266
})
277267

278-
console.log("Open Issues:", data.repository.issues.nodes)
279-
console.log("Open PRs:", data.repository.pullRequests.nodes)
268+
console.log("Issues found:", data.search.nodes)
280269
```
281270

282271
The GraphQL method supports TypeScript generics for type safety:

0 commit comments

Comments
 (0)