Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Get query's operation name from vars (#64) #165

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:8
- image: circleci/node:10
steps:
- checkout
- run: yarn install
- run: yarn test
- run: yarn test:ci
- run: npx semantic-release
Empty file added .github/renovate.json
Empty file.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const query = `{
}
}`

request('https://api.graph.cool/simple/v1/movies', query).then(data =>
console.log(data)
)
request('https://api.graph.cool/simple/v1/movies', query).then((data) => console.log(data))
```

## Usage
Expand All @@ -43,11 +41,11 @@ request('https://api.graph.cool/simple/v1/movies', query).then(data =>
import { request, GraphQLClient } from 'graphql-request'

// Run GraphQL queries/mutations using a static function
request(endpoint, query, variables).then(data => console.log(data))
request(endpoint, query, variables).then((data) => console.log(data))

// ... or create a GraphQL client instance to send requests
const client = new GraphQLClient(endpoint, { headers: {} })
client.request(query, variables).then(data => console.log(data))
client.request(query, variables).then((data) => console.log(data))
```

## Examples
Expand Down Expand Up @@ -81,7 +79,7 @@ async function main() {
console.log(JSON.stringify(data, undefined, 2))
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

[TypeScript Source](examples/authentication-via-http-header.ts)
Expand Down Expand Up @@ -114,7 +112,7 @@ async function main() {
console.log(JSON.stringify(data, undefined, 2))
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

[TypeScript Source](examples/passing-more-options-to-fetch.ts)
Expand Down Expand Up @@ -146,7 +144,7 @@ async function main() {
console.log(JSON.stringify(data, undefined, 2))
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

[TypeScript Source](examples/using-variables.ts)
Expand Down Expand Up @@ -179,7 +177,7 @@ async function main() {
}
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

[TypeScript Source](examples/error-handling)
Expand Down Expand Up @@ -207,7 +205,7 @@ async function main() {
console.log(JSON.stringify(data, undefined, 2))
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

### Cookie support for `node`
Expand Down Expand Up @@ -245,7 +243,7 @@ async function main() {
console.log(JSON.stringify(data, undefined, 2))
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

[TypeScript Source](examples/cookie-support-for-node)
Expand All @@ -272,16 +270,11 @@ async function main() {
}
`

const { data, errors, extensions, headers, status } = await rawRequest(
endpoint,
query
)
console.log(
JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2)
)
const { data, errors, extensions, headers, status } = await rawRequest(endpoint, query)
console.log(JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2))
}

main().catch(error => console.error(error))
main().catch((error) => console.error(error))
```

[TypeScript Source](examples/receiving-a-raw-response)
Expand Down
5 changes: 2 additions & 3 deletions examples/authentication-via-http-header.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GraphQLClient } from '../src'

;(async function() {
;(async function () {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const graphQLClient = new GraphQLClient(endpoint, {
Expand All @@ -26,4 +25,4 @@ import { GraphQLClient } from '../src'

const data = await graphQLClient.request<TData>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
})().catch((error) => console.error(error))
22 changes: 11 additions & 11 deletions examples/cookie-support-for-node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require('fetch-cookie/node-fetch')(require('node-fetch'))
// tslint:disable-next-line
;(global as any).fetch = require('fetch-cookie/node-fetch')(require('node-fetch'))

import { GraphQLClient } from '../src'

;(async function() {
;(async function () {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const graphQLClient = new GraphQLClient(endpoint, {
Expand All @@ -12,20 +12,20 @@ import { GraphQLClient } from '../src'
})

const query = /* GraphQL */ `
{
Movie(title: "Inception") {
releaseDate
actors {
name
}
{
Movie(title: "Inception") {
releaseDate
actors {
name
}
}
`
}
`

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))
})().catch((error) => console.error(error))
5 changes: 2 additions & 3 deletions examples/error-handling.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { request } from '../src'

;(async function() {
;(async function () {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const query = /* GraphQL */ `
Expand All @@ -25,4 +24,4 @@ import { request } from '../src'
console.error(JSON.stringify(error, undefined, 2))
process.exit(1)
}
})().catch(error => console.error(error))
})().catch((error) => console.error(error))
5 changes: 2 additions & 3 deletions examples/passing-more-options-to-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GraphQLClient } from '../src'

;(async function() {
;(async function () {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const graphQLClient = new GraphQLClient(endpoint, {
Expand All @@ -25,4 +24,4 @@ import { GraphQLClient } from '../src'

const data = await graphQLClient.request<TData>(query)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
})().catch((error) => console.error(error))
14 changes: 4 additions & 10 deletions examples/receiving-a-raw-response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { rawRequest } from '../src'

;(async function() {
;(async function () {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const query = /* GraphQL */ `
Expand All @@ -18,11 +17,6 @@ import { rawRequest } from '../src'
Movie: { releaseDate: string; actors: Array<{ name: string }> }
}

const { data, errors, extensions, headers, status } = await rawRequest<TData>(
endpoint,
query
)
console.log(
JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2)
)
})().catch(error => console.error(error))
const { data, errors, extensions, headers, status } = await rawRequest<TData>(endpoint, query)
console.log(JSON.stringify({ data, errors, extensions, headers, status }, undefined, 2))
})().catch((error) => console.error(error))
5 changes: 2 additions & 3 deletions examples/using-variables.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { request } from '../src'

;(async function() {
;(async function () {
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'

const query = /* GraphQL */ `
Expand All @@ -24,4 +23,4 @@ import { request } from '../src'

const data = await request<TData>(endpoint, query, variables)
console.log(JSON.stringify(data, undefined, 2))
})().catch(error => console.error(error))
})().catch((error) => console.error(error))
27 changes: 16 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,31 @@
"bugs": {
"url": "https://github.com/prisma/graphql-request/issues"
},
"engines": {
"node": ">=10"
},
"homepage": "https://github.com/prisma/graphql-request",
"scripts": {
"format": "prettier --write .",
"prepublish": "npm run build",
"build": "rm -rf dist && tsc -d",
"lint": "tslint --project . {examples,src,test}/**/*.ts",
"test": "npm run lint && npm run build && ava --serial && npm run size",
"size": "bundlesize"
},
"dependencies": {
"cross-fetch": "2.2.2"
"test": "yarn lint && yarn build && ava --serial",
"test:ci": "yarn test && bundlesize"
},
"dependencies": {},
"devDependencies": {
"@prisma-labs/prettier-config": "^0.1.0",
"@types/fetch-mock": "5.12.2",
"@types/node": "8.5.5",
"ava": "0.25.0",
"bundlesize": "0.17.0",
"ava": "^3.8.2",
"bundlesize": "^0.18.0",
"fetch-cookie": "0.7.2",
"fetch-mock": "5.13.1",
"tslint": "5.9.1",
"tslint-config-standard": "7.0.0",
"typescript": "2.7.2"
}
"prettier": "^2.0.5",
"tslint": "5.11.0",
"tslint-config-standard": "8.0.1",
"typescript": "3.0.3"
},
"prettier": "@prisma-labs/prettier-config"
}
6 changes: 0 additions & 6 deletions renovate.json

This file was deleted.

Loading