graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

Type with name "Upload" does not exists

Open andrewmartin opened this issue 3 years ago • 3 comments

Hi there,

I'm continually getting this error when I'm trying to use Upload scalar within my schema. I've followed and read a ton of posts and SO links but can't seem to get past this.

3|server:watch         |       throw new Error(`Type with name ${(0, _misc.inspect)(typeName)} does not exists`);
3|server:watch         |       ^
3|server:watch         | Error: Type with name "Upload" does not exists
3|server:watch         |     at SchemaComposer.get (/Users/andrewmartin/code/server/node_modules/graphql-compose/lib/TypeStorage.js:44:13)

This happens when I try to add the field directly like so:

UserTC.addFields({
  image: 'Upload',
})

I'm trying to add an Upload type. This type, by the way, works successfully against my schema and in non-compose / TC resolvers:

const schemaPath = join(__dirname, '../../../src/gql/schema/**/*.graphql')

const schemaFiles = loadSchemaSync(schemaPath, {
  loaders: [new GraphQLFileLoader()],
})

logger.info(`loaded schema! from path: ${schemaPath}`)

const uploadSchema = makeExecutableSchema({
  typeDefs: `scalar Upload`,
  resolvers: { Upload: GraphQLUpload },
})

const schemaComposer = new SchemaComposer(uploadSchema)

export const schemaWithResolvers = addResolversToSchema({
  resolvers,
  schema: schemaFiles,
})

schemaComposer.merge(schemaWithResolvers)

schemaComposer.Query.addFields({
  ...UserQuery,
  ...PageQuery,
  ...MenuQuery,
})

schemaComposer.Mutation.addFields({
  ...adminAccess(UserMutation),
  ...adminAccess(PageMutation),
  ...MenuMutation,
})

schemaComposer.merge(schemaWithResolvers)

export const schema = schemaComposer.buildSchema()

Main part of interest is here:

const uploadSchema = makeExecutableSchema({
  typeDefs: `scalar Upload`,
  resolvers: { Upload: GraphQLUpload },
})

I've seen some weird workarounds people are doing to add it successfully when Mutation.addFields is hit, but that won't work well for my case because I want to simply add a new argument onto the types available. Any workarounds?

Thanks in advance for your help.

andrewmartin avatar Apr 12 '21 04:04 andrewmartin

I've added scalars before via createScalarTC. Does calling schemaComposer.createScalarTC(GraphQLUpload) instead of making a separate upload schema work?

canac avatar Aug 26 '21 16:08 canac

I'm seeing the same error when trying to use addFields and the Upload type. In my case, I've noticed it after converting from composeWithMongoose and getResolver to composeMongoose and mongooseResolvers using [email protected]. I do not see the error when using composeWithMongoose. I'm unsure if it's related or not, but just wanted to mention it.

@andrewmartin Which compose function are you using to create your TCs?

corydeppen avatar Oct 31 '21 04:10 corydeppen