Skip to content

Commit

Permalink
Merge pull request #110 from brikou/feature/examples_ts_typings_only
Browse files Browse the repository at this point in the history
Add TS typings to examples
  • Loading branch information
Divyendu Singh committed Sep 20, 2018
2 parents 9f3fd07 + 4c6e037 commit 70d3555
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 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
6 changes: 5 additions & 1 deletion examples/authentication-via-http-header.ts
Expand Up @@ -20,6 +20,10 @@ import { GraphQLClient } from '../src'
}
`

const data = await graphQLClient.request(query)
interface TData {
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}

const data = await graphQLClient.request<TData>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
6 changes: 5 additions & 1 deletion examples/cookie-support-for-node.ts
Expand Up @@ -22,6 +22,10 @@ import { GraphQLClient } from '../src'
}
`

const data = await graphQLClient.rawRequest(query)
interface TData {
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}

const data = await graphQLClient.rawRequest<TData>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
6 changes: 5 additions & 1 deletion examples/error-handling.ts
Expand Up @@ -14,8 +14,12 @@ import { request } from '../src'
}
`

interface TData {
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}

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

const data = await graphQLClient.request(query)
interface TData {
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}

const data = await graphQLClient.request<TData>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
6 changes: 5 additions & 1 deletion examples/receiving-a-raw-response.ts
Expand Up @@ -14,7 +14,11 @@ import { rawRequest } from '../src'
}
`

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

const { data, errors, extensions, headers, status } = await rawRequest<TData>(
endpoint,
query
)
Expand Down
6 changes: 5 additions & 1 deletion examples/using-variables.ts
Expand Up @@ -18,6 +18,10 @@ import { request } from '../src'
title: 'Inception',
}

const data = await request(endpoint, query, variables)
interface TData {
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}

const data = await request<TData>(endpoint, query, variables)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))

0 comments on commit 70d3555

Please sign in to comment.