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

update to handle graphql v16_x breaking changes #495

Merged
merged 16 commits into from Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
@@ -1,5 +1,10 @@
### vNEXT

### v3.1.2 (June 11, 2023)

#### Updated
- [#495](https://github.com/join-monster/join-monster/pull/495): Added support for GraphQL v16_6_0. There were a number of breaking changes introduced in GraphQL v16 and these impacted a large number of tests and bit of the code. This provides fixes for those breaking changes.

### v3.1.1 (January 17, 2022)

#### Fixed
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -77,7 +77,7 @@
},
"homepage": "https://github.com/join-monster/join-monster#readme",
"peerDependencies": {
"graphql": "^15.4.0"
"graphql": "^16.6.0"
bueche marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@ava/babel": "^1.0.1",
Expand All @@ -97,7 +97,7 @@
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.11.0",
"faker": "^4.1.0",
"graphql": "^15.4.0",
"graphql": "^16.6.0",
"graphsiql": "0.2.0",
"idx": "^2.5.6",
"jsdoc-to-markdown": "^5.0.0",
Expand All @@ -120,7 +120,7 @@
"debug": "^4.1.0",
"deprecate": "^1.0.0",
"generatorics": "^1.0.8",
"graphql-relay": "^0.6.0",
"graphql-relay": "^0.10.0",
"lodash": "^4.17.15"
}
}
4 changes: 2 additions & 2 deletions src/index.js
Expand Up @@ -153,7 +153,7 @@ async function getNode(
node: {
type,
name: type.name.toLowerCase(),
args: {},
args: [],
extensions: {
joinMonster: {
where
Expand Down Expand Up @@ -184,7 +184,7 @@ async function getNode(
)
await nextBatch(sqlAST, data, dbCall, context, options)
if (!data) return data
data.__type__ = type
data.__type__ = type.name
return data
}

Expand Down
2 changes: 1 addition & 1 deletion test-api/schema-paginated/User.js
Expand Up @@ -478,7 +478,7 @@ const User = new GraphQLObjectType({
})
})

const connectionConfig = { nodeType: GraphQLNonNull(User) }
const connectionConfig = { nodeType: new GraphQLNonNull(User) }
if (PAGINATE === 'offset') {
connectionConfig.connectionFields = {
total: { type: GraphQLInt }
Expand Down
117 changes: 55 additions & 62 deletions test/columns.js
@@ -1,8 +1,7 @@
import test from 'ava'
import { graphql } from 'graphql'
import { toGlobalId } from 'graphql-relay'
import schemaBasic from '../test-api/schema-basic/index'
import { partial } from 'lodash'
import schema from '../test-api/schema-basic/index'
import { errCheck } from './_util'

function wrap(query) {
Expand All @@ -11,20 +10,19 @@ function wrap(query) {
}`
}

const run = partial(graphql, schemaBasic)

test('get a field with the same name as the SQL column', async t => {
const query = wrap('id')
const { data, errors } = await run(query)
const source = wrap('id')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
t.deepEqual(data, {
users: [{ id: 1 }, { id: 2 }, { id: 3 }]
})
})

test('get a field with a different SQL column name and field name', async t => {
const query = wrap('email')
const { data, errors } = await run(query)
const source = wrap('email')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
t.deepEqual(data, {
users: [
Expand All @@ -36,17 +34,17 @@ test('get a field with a different SQL column name and field name', async t => {
})

test('get a field that has a resolver on top of the SQL column', async t => {
const query = wrap('idEncoded')
const { data, errors } = await run(query)
const source = wrap('idEncoded')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
t.deepEqual(data, {
users: [{ idEncoded: 'MQ==' }, { idEncoded: 'Mg==' }, { idEncoded: 'Mw==' }]
})
})

test('get a globalID field', async t => {
const query = wrap('globalId')
const { data, errors } = await run(query)
const source = wrap('globalId')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
t.deepEqual(data, {
users: [
Expand All @@ -58,8 +56,8 @@ test('get a globalID field', async t => {
})

test('get a field that depends on multiple sql columns', async t => {
const query = wrap('fullName')
const { data, errors } = await run(query)
const source = wrap('fullName')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
t.deepEqual(data, {
users: [
Expand All @@ -71,8 +69,8 @@ test('get a field that depends on multiple sql columns', async t => {
})

test('it should disambiguate two entities with identical fields', async t => {
const query = wrap('numLegs')
const { data, errors } = await run(query)
const source = wrap('numLegs')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [
Expand All @@ -85,15 +83,15 @@ test('it should disambiguate two entities with identical fields', async t => {
})

test('it should handle fragments at the top level', async t => {
const query = `
const source = `
{
users {
...F0
}
}
fragment F0 on User { id }
`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [{ id: 1 }, { id: 2 }, { id: 3 }]
Expand All @@ -102,14 +100,14 @@ test('it should handle fragments at the top level', async t => {
})

test('it should handle an inline fragment', async t => {
const query = `
const source = `
{
users {
... on User { fullName }
}
}
`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [
Expand All @@ -122,7 +120,7 @@ test('it should handle an inline fragment', async t => {
})

test('it should handle nested fragments', async t => {
const query = `
const source = `
{
users {
... on User {
Expand All @@ -134,7 +132,7 @@ test('it should handle nested fragments', async t => {
id, fullName, email
}
`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [
Expand All @@ -147,7 +145,7 @@ test('it should handle nested fragments', async t => {
})

test('it should handle named fragments on an interface', async t => {
const query = `
const source = `
{
sponsors {
...info
Expand All @@ -167,7 +165,7 @@ test('it should handle named fragments on an interface', async t => {
}
}
`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
sponsors: [
Expand All @@ -183,7 +181,7 @@ test('it should handle named fragments on an interface', async t => {
})

test('it should handle inline fragments on an interface', async t => {
const query = `
const source = `
{
sponsors {
...on Person {
Expand All @@ -209,7 +207,7 @@ test('it should handle inline fragments on an interface', async t => {
}
}
`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
sponsors: [
Expand All @@ -225,8 +223,8 @@ test('it should handle inline fragments on an interface', async t => {
})

test('it should handle a column that resolves independantly of SQL', async t => {
const query = wrap('id, favNums')
const { data, errors } = await run(query)
const source = wrap('id, favNums')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [
Expand All @@ -239,12 +237,12 @@ test('it should handle a column that resolves independantly of SQL', async t =>
})

test('it should handle a query that gets nothing from the database', async t => {
const query = `{
const source = `{
user(id:2) {
favNums
}
}`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
user: { favNums: [1, 2, 3] }
Expand All @@ -253,8 +251,8 @@ test('it should handle a query that gets nothing from the database', async t =>
})

test('it should handle duplicate fields', async t => {
const query = wrap('id id id id idEncoded fullName fullName')
const { data, errors } = await run(query)
const source = wrap('id id id id idEncoded fullName fullName')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [
Expand All @@ -267,8 +265,8 @@ test('it should handle duplicate fields', async t => {
})

test('it should not be tripped up by the introspection queries', async t => {
const query = wrap('__typename')
const { data, errors } = await run(query)
const source = wrap('__typename')
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
const expect = {
users: [
Expand All @@ -281,22 +279,21 @@ test('it should not be tripped up by the introspection queries', async t => {
})

test('it should handle numeric variables', async t => {
const query = `
const source = `
query user($userId: Int) {
user(id: $userId) {
id
fullName
}
}
`
const variables = { userId: 1 }
const { data, errors } = await graphql(
schemaBasic,
query,
null,
null,
variables
)

const variableValues = { userId: 1 }
const { data, errors } = await graphql({
schema,
source,
variableValues
})
errCheck(t, errors)
const expect = {
user: {
Expand All @@ -308,22 +305,20 @@ test('it should handle numeric variables', async t => {
})

test('it should handle string variables', async t => {
const query = `
const source = `
query user($encodedUserId: String) {
user(idEncoded: $encodedUserId) {
idEncoded
fullName
}
}
`
const variables = { encodedUserId: 'MQ==' }
const { data, errors } = await graphql(
schemaBasic,
query,
null,
null,
variables
)
const variableValues = { encodedUserId: 'MQ==' }
const { data, errors } = await graphql({
schema,
source,
variableValues
})
errCheck(t, errors)
const expect = {
user: {
Expand All @@ -335,21 +330,19 @@ test('it should handle string variables', async t => {
})

test('it should handle boolean variables', async t => {
const query = `
const source = `
query sponsors($filter: Boolean) {
sponsors(filterLegless: $filter) {
numLegs
}
}
`
const variables = { filter: true }
const { data, errors } = await graphql(
schemaBasic,
query,
null,
null,
variables
)
const variableValues = { filter: true }
const { data, errors } = await graphql({
schema,
source,
variableValues
})
errCheck(t, errors)
const expect = {
sponsors: []
Expand All @@ -358,13 +351,13 @@ test('it should handle boolean variables', async t => {
})

test('it should handle raw SQL expressions', async t => {
const query = `{
const source = `{
user(id: 2) {
fullName
capitalizedLastName
}
}`
const { data, errors } = await run(query)
const { data, errors } = await graphql({schema, source})
errCheck(t, errors)
t.is(
data.user.fullName.split(' ')[1].toUpperCase(),
Expand Down