Skip to content

Commit

Permalink
Use TData interface
Browse files Browse the repository at this point in the history
  • Loading branch information
brikou committed Sep 19, 2018
1 parent a0dbcf0 commit 4c6e037
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions examples/authentication-via-http-header.ts
Expand Up @@ -20,8 +20,10 @@ import { GraphQLClient } from '../src'
}
`

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

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

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

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

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

try {
const data = await request<{
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}>(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: 4 additions & 2 deletions examples/passing-more-options-to-fetch.ts
Expand Up @@ -19,8 +19,10 @@ import { GraphQLClient } from '../src'
}
`

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

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

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

const { data, errors, extensions, headers, status } = await rawRequest<TData>(
endpoint,
query
)
console.log(
JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2)
)
Expand Down
6 changes: 4 additions & 2 deletions examples/using-variables.ts
Expand Up @@ -18,8 +18,10 @@ import { request } from '../src'
title: 'Inception',
}

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

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

0 comments on commit 4c6e037

Please sign in to comment.