Skip to content

Commit

Permalink
Add TS typings to example
Browse files Browse the repository at this point in the history
  • Loading branch information
brikou committed Sep 17, 2018
1 parent 62c0f75 commit a0dbcf0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -290,7 +290,6 @@ main().catch(error => console.error(error))

- Fragments
- Using [`graphql-tag`](https://github.com/apollographql/graphql-tag)
- Typed Typescript return values

## FAQ

Expand Down
4 changes: 3 additions & 1 deletion examples/authentication-via-http-header.ts
Expand Up @@ -20,6 +20,8 @@ import { GraphQLClient } from '../src'
}
`

const data = await graphQLClient.request(query)
const data = await graphQLClient.request<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
4 changes: 3 additions & 1 deletion examples/cookie-support-for-node.ts
Expand Up @@ -22,6 +22,8 @@ import { GraphQLClient } from '../src'
}
`

const data = await graphQLClient.rawRequest(query)
const data = await graphQLClient.rawRequest<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
4 changes: 3 additions & 1 deletion examples/error-handling.ts
Expand Up @@ -15,7 +15,9 @@ import { request } from '../src'
`

try {
const data = await request(endpoint, query)
const data = await request<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(endpoint, query)
console.log(JSON.stringify(data, undefined, 2))
} catch (error) {
console.error(JSON.stringify(error, undefined, 2))
Expand Down
4 changes: 3 additions & 1 deletion examples/passing-more-options-to-fetch.ts
Expand Up @@ -19,6 +19,8 @@ import { GraphQLClient } from '../src'
}
`

const data = await graphQLClient.request(query)
const data = await graphQLClient.request<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
8 changes: 4 additions & 4 deletions examples/receiving-a-raw-response.ts
Expand Up @@ -14,10 +14,10 @@ import { rawRequest } from '../src'
}
`

const { data, errors, extensions, headers, status } = await rawRequest(
endpoint,
query
)
const { data, errors, extensions, headers, status } = await rawRequest<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(endpoint, query)

console.log(
JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2)
)
Expand Down
4 changes: 3 additions & 1 deletion examples/using-variables.ts
Expand Up @@ -18,6 +18,8 @@ import { request } from '../src'
title: 'Inception',
}

const data = await request(endpoint, query, variables)
const data = await request<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(endpoint, query, variables)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))

0 comments on commit a0dbcf0

Please sign in to comment.