Apollo-server: Apollo server 2.0. Type “Upload” not found in document

Created on 9 Jul 2018  Â·  4Comments  Â·  Source: apollographql/apollo-server

How to replicate:

server.js

const { ApolloServer, makeExecutableSchema, gql } = require('apollo-server');

const typeDefs = gql`
type Mutation {
    uploadAvatar(upload: Upload!): String!
}
`;
const resolvers = {
    Mutation: {
        uploadAvatar(root, args, context, info) {
            return 'test';
        }
    }
  };

const schema = makeExecutableSchema({ typeDefs, resolvers });

const server = new ApolloServer({
  schema,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

package.json

"dependencies": {
    "apollo-server": "^2.0.0-rc.6",
    "graphql": "^0.13.2"
  }

On node server.js we get the following error:

Type "Upload" not found in document.

Given the latest version of apollo server, am I supposed to add anything else to the query? According to this tutorial and few other sources that I currently cannot recall, one does not need to do anything more than just write Upload and it should work fine. Am I missing anything?

has-reproduction

Most helpful comment

Hello @zenVentzi Sorry about the confusion, when you pass in your own executable schema like you have done above using the schema param in the ApolloServer constructor, you'll need to manually add the scalar Upload in your typeDefs like so:

const typeDefs = gql`
scalar Upload

type Mutation {
    uploadAvatar(upload: Upload!): String!
}
`;

All 4 comments

By the sounds of the error, I don't think it's an issue with apollo-upload-server. Are you able to provide a more detailed error trace?

For reference, here is the new location of the file upload docs: https://www.apollographql.com/docs/guides/file-uploads.html

Hello @zenVentzi Sorry about the confusion, when you pass in your own executable schema like you have done above using the schema param in the ApolloServer constructor, you'll need to manually add the scalar Upload in your typeDefs like so:

const typeDefs = gql`
scalar Upload

type Mutation {
    uploadAvatar(upload: Upload!): String!
}
`;

We've fixed this in the most recent release and with https://www.apollographql.com/docs/guides/file-uploads.html#File-upload-with-schema-param

Wow, that was quick! Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings