Skip to content

Commit

Permalink
feat: upgrade to graphql@14
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Sep 12, 2018
1 parent 6865e4a commit 4134b3e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/node-fetch": "1.6.7",
"ava": "0.25.0",
"cpx": "1.5.0",
"graphql": "0.13.2",
"graphql": "14.0.2",
"rimraf": "2.6.2",
"tslint": "5.9.1",
"tslint-config-standard": "7.0.0",
Expand Down
23 changes: 15 additions & 8 deletions src/__tests__/basic/findGraphQLConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ import test from 'ava'
import { dirname, join } from 'path'
import { mkdtempSync } from 'fs'
import { tmpdir } from 'os'
const schema = require('../schema.json')
import { findGraphQLConfigFile, ConfigNotFoundError } from '../../'

test('returns a correct config filename', (t) => {
test('returns a correct config filename', t => {
const configFile = findGraphQLConfigFile(__dirname)
t.deepEqual(configFile, join(__dirname, '.graphqlconfig'))
});
})

test('returns a correct config filename for 1st level of sub directories', (t) => {
const configFile = findGraphQLConfigFile(`${__dirname}/../sub-directory-config`)
t.deepEqual(configFile, join(`${__dirname}/../sub-directory-config/sub-directory-2`, '.graphqlconfig'))
});
test('returns a correct config filename for 1st level of sub directories', t => {
const configFile = findGraphQLConfigFile(
`${__dirname}/../sub-directory-config`,
)
t.deepEqual(
configFile,
join(
`${__dirname}/../sub-directory-config/sub-directory-2`,
'.graphqlconfig',
),
)
})

test('throws GraphQLConfigNotFoundError when config is not found', (t) => {
test('throws GraphQLConfigNotFoundError when config is not found', t => {
const tempDir = mkdtempSync(join(tmpdir(), 'graphql-config'))
t.throws(() => findGraphQLConfigFile(tempDir), ConfigNotFoundError)
})
5 changes: 3 additions & 2 deletions src/__tests__/basic/getGraphQLConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import test from 'ava'
import { join, resolve } from 'path'
import { printSchema } from 'graphql'
const schema = require('../schema.json')
import { getGraphQLConfig, GraphQLConfig } from '../../'

const CONFIG_DIR = join(__dirname, 'config')
Expand All @@ -18,7 +17,9 @@ test('returns a correct name', t => {
})

test('returns config for file', t => {
const testWithSchemaConfig = config.getConfigForFile(resolve('./config/schema-a.graphql'))
const testWithSchemaConfig = config.getConfigForFile(
resolve('./config/schema-a.graphql'),
)
if (testWithSchemaConfig) {
t.deepEqual(testWithSchemaConfig.projectName, 'testWithSchema')
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/basic/getGraphQLProjectConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import test from 'ava'
const schema = require('../schema.json')
import { getGraphQLProjectConfig } from '../../'

test('resolves schema from file', async (t) => {
test('resolves schema from file', async t => {
const config = getGraphQLProjectConfig(__dirname)
const resolvedSchema = await config.resolveIntrospection()

t.deepEqual(resolvedSchema, schema)
t.snapshot(resolvedSchema)
})
67 changes: 37 additions & 30 deletions src/__tests__/endpoint-extension/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import test from 'ava'
import { graphql, introspectionQuery } from 'graphql'
import { GraphQLProjectConfig, GraphQLEndpointsExtension } from '../../'
import { GraphQLProjectConfig } from '../../'
import { serveSchema } from '../utils'
const introspection = require('../schema.json')

test.before(async (t) => {
test.before(async t => {
return await serveSchema()
})


const confPath = `${__dirname}/.graphqlconfig`

test('getEndpointsMap when endpoint is string url', async (t) => {
test('getEndpointsMap when endpoint is string url', async t => {
const configData = {
schemaPath: '../schema.json',
extensions: {
Expand All @@ -23,10 +21,12 @@ test('getEndpointsMap when endpoint is string url', async (t) => {

const config = new GraphQLProjectConfig(configData, confPath)
const endpoints = config.endpointsExtension
t.deepEqual(endpoints && endpoints.getRawEndpointsMap(), { dev: { url: 'http://default' }})
t.deepEqual(endpoints && endpoints.getRawEndpointsMap(), {
dev: { url: 'http://default' },
})
})

test('getEndpointsMap when endpoint is single endpoint config', async (t) => {
test('getEndpointsMap when endpoint is single endpoint config', async t => {
const configData = {
schemaPath: '../schema.json',
extensions: {
Expand All @@ -43,10 +43,12 @@ test('getEndpointsMap when endpoint is single endpoint config', async (t) => {

const config = new GraphQLProjectConfig(configData, confPath, undefined)
const endpoint = config.endpointsExtension
t.deepEqual(endpoint && endpoint.getRawEndpointsMap(), { dev: configData.extensions.endpoints.dev })
t.deepEqual(endpoint && endpoint.getRawEndpointsMap(), {
dev: configData.extensions.endpoints.dev,
})
})

test('getEndpointsMap when endpoint is endpoints map', async (t) => {
test('getEndpointsMap when endpoint is endpoints map', async t => {
const configData = {
schemaPath: '../schema.json',
extensions: {
Expand All @@ -65,22 +67,20 @@ test('getEndpointsMap when endpoint is endpoints map', async (t) => {
const config = new GraphQLProjectConfig(configData, confPath, undefined)

const endpoint = config.endpointsExtension
t.deepEqual(endpoint && endpoint.getRawEndpointsMap(),
{
dev: {
url: 'http://dev',
t.deepEqual(endpoint && endpoint.getRawEndpointsMap(), {
dev: {
url: 'http://dev',
},
prod: {
url: 'http://prod',
subscription: {
url: 'ws://prod',
},
prod: {
url: 'http://prod',
subscription: {
url: 'ws://prod',
},
}
}
)
},
})
})

test('resolveSchemaFromEndpoint should throw if non-existing endpoint is specified', async (t) => {
test('resolveSchemaFromEndpoint should throw if non-existing endpoint is specified', async t => {
const configData = {
schemaPath: '../schema.json',
extensions: {
Expand All @@ -97,25 +97,32 @@ test('resolveSchemaFromEndpoint should throw if non-existing endpoint is specifi
const config = new GraphQLProjectConfig(configData, confPath, undefined)
let error
const endpoint = config.endpointsExtension
error = t.throws(() => endpoint && endpoint.getEndpoint('prod').resolveSchema())
t.regex(error.message, /"prod" is not valid endpoint name. Valid endpoint names: dev/)
error = t.throws(
() => endpoint && endpoint.getEndpoint('prod').resolveSchema(),
)
t.regex(
error.message,
/"prod" is not valid endpoint name. Valid endpoint names: dev/,
)
})

test('resolveSchemaFromEndpoint HTTP', async (t) => {
test('resolveSchemaFromEndpoint HTTP', async t => {
const configData = {
schemaPath: '../schema.json',
extensions: {
endpoints: {
dev: 'http://127.0.0.1:33333'
}
dev: 'http://127.0.0.1:33333',
},
},
}

const config = new GraphQLProjectConfig(configData, confPath, undefined)
if (!config.endpointsExtension){
if (!config.endpointsExtension) {
throw 'endpointExtension can\'t be empty'
}
const schema = await config.endpointsExtension.getEndpoint('dev').resolveSchema()
const schema = await config.endpointsExtension
.getEndpoint('dev')
.resolveSchema()
const resolvedIntrospection = await graphql(schema, introspectionQuery)
t.deepEqual(resolvedIntrospection, introspection)
t.snapshot(resolvedIntrospection)
})
1 change: 0 additions & 1 deletion src/__tests__/introspection-query/getSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import test from 'ava'
import { join } from 'path'
import { printSchema } from 'graphql'
const schema = require('../schema.json')
import { getGraphQLConfig, GraphQLConfig } from '../../'

test('reads single schema', t => {
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/yaml/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import test from 'ava'
const schema = require('../schema.json')
import { getGraphQLProjectConfig } from '../../'

test(async (t) => {
test(async t => {
const config = getGraphQLProjectConfig(__dirname)
const resolvedSchema = await config.resolveIntrospection()

t.deepEqual(resolvedSchema, schema)
t.snapshot(resolvedSchema)
})
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1370,11 +1370,11 @@ graphql-request@^1.5.0:
dependencies:
cross-fetch "1.1.1"

graphql@0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270"
graphql@14.0.2:
version "14.0.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.0.2.tgz#7dded337a4c3fd2d075692323384034b357f5650"
dependencies:
iterall "^1.2.1"
iterall "^1.2.2"

har-schema@^1.0.5:
version "1.0.5"
Expand Down Expand Up @@ -1703,7 +1703,7 @@ isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"

iterall@^1.2.1:
iterall@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"

Expand Down

0 comments on commit 4134b3e

Please sign in to comment.