Last active
March 6, 2020 21:37
-
-
Save sockol/782e4be26dc2ab19cf588b1378c59e34 to your computer and use it in GitHub Desktop.
Unit test file uploads in your Apollo GraphQL Server
This file contains hidden or 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
const apolloTesting = require(`apollo-server-testing`); | |
const { | |
ApolloServer | |
} = require(`apollo-server-express`); | |
// see docs at: https://www.apollographql.com/docs/apollo-server/getting-started/ | |
const serverConfig = { | |
/* | |
typeDefs, | |
resolvers, | |
context, | |
*/ | |
} | |
const testServer = new ApolloServer({ | |
...serverConfig, | |
}); | |
const client = apolloTesting.createTestClient(testServer); | |
it(`addFile`, async function() { | |
try { | |
const filename = `some-powerpoint.pptx` | |
const file = fs.createReadStream(resolve(`./tests/${filename}`)); | |
const QUERY = ` | |
mutation addFile($file: Upload!) { | |
addFile(file: $file) { | |
id | |
} | |
} | |
`; | |
const d = await client.mutate({ | |
query: QUERY, | |
variables: { | |
file, | |
}, | |
}); | |
if (d.errors) | |
throw new Error(d.errors); | |
assert(d.data.addFile); | |
} catch (error) { | |
throw new Error(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does
resolve
refer to?