Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const { | ||
GraphQLString, | ||
GraphQLSchema, | ||
GraphQLObjectType, | ||
GraphQLBoolean, | ||
execute, | ||
parse | ||
} = require('graphql') | ||
const t = require('tap') | ||
const GraphQLUpload = require('./GraphQLUpload') | ||
const snapshotError = require('./test-helpers/snapshotError') | ||
|
||
t.test('Missing entry for upload scalar.', async t => { | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'Query', | ||
fields: { | ||
image: { | ||
description: 'Uploads an image.', | ||
type: GraphQLString, | ||
args: { | ||
name: { | ||
description: 'Image name.', | ||
type: GraphQLString | ||
} | ||
}, | ||
async resolve(parent, { image }) { | ||
t.type(image, Promise, 'Upload must be a Promise') | ||
try { | ||
await image | ||
throw new Error('Upload must throw!') | ||
} catch (error) { | ||
t.matchSnapshot(snapshotError(error), 'Middleware throws.') | ||
} | ||
|
||
return true | ||
} | ||
} | ||
} | ||
}), | ||
mutation: new GraphQLObjectType({ | ||
name: 'Mutation', | ||
fields: { | ||
uploadImage: { | ||
description: 'Uploads an image.', | ||
type: GraphQLBoolean, | ||
args: { | ||
image: { | ||
description: 'Image file.', | ||
type: GraphQLUpload | ||
} | ||
}, | ||
async resolve(parent, { image }) { | ||
t.type(image, Promise, 'Upload must be a Promise') | ||
try { | ||
await image | ||
throw new Error('Upload must throw!') | ||
} catch (error) { | ||
t.matchSnapshot(snapshotError(error), 'Middleware throws.') | ||
} | ||
|
||
return true | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
await execute({ | ||
schema, | ||
document: parse( | ||
`mutation ($image: Upload!) { | ||
uploadImage(image: $image) | ||
}` | ||
), | ||
rootValue: {}, | ||
contextValue: {}, | ||
variableValues: { image: 'this is invalid' } | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`GraphQLUpload.test.js TAP Missing entry for upload scalar. > Middleware throws. 1`] = ` | ||
{ | ||
"name": "Error", | ||
"message": "\`Upload\` scalars must have a corresponding multipart file." | ||
} | ||
` |