jaydenseric / graphql-upload

Middleware and a scalar Upload to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 132 forks source link

Scalar Upload generated type from graphql-binding as a string #101

Closed thanatchakromsang closed 6 years ago

thanatchakromsang commented 6 years ago

2018-08-15-143201_1310x96_escrotum

is it suppose to be like this below?

export type Upload = {
      stream: NodeJS.ReadableStream
      filename: string
      mimtype: string
      encoding: string
}
jaydenseric commented 6 years ago

I'm not sure exactly what that library and the type is about, but the Upload scalar represents a Promise, that resolves an object like you noted (for the current version, it's about to change a little). It can't be serialized.

thanatchakromsang commented 6 years ago

@jaydenseric Thanks for short notice on the upcoming version!, as for the library it's an auto-generated type for schema but put that aside I still don't know what cause it to be like that

jaydenseric commented 6 years ago

Well, here is the source for the GraphQLUpload scalar: https://github.com/jaydenseric/apollo-upload-server/blob/v6.0.0-alpha.1/src/types.mjs#L3

Is there a way it can somehow be improved so auto-generated types are more useful? Does a type make sense in this context? Perhaps this is really an issue to be solved in the auto-type-generation library.

mike-marcacci commented 6 years ago

Hey @thanatchakromsang what generator are you using for that type system? Using apollo-cli you can use --passthroughCustomScalars and --customScalarsPrefix for both Flow and TypeScript generators, which allows you to define types for custom scalars.

For example, I use:

apollo codegen:generate --clientSchema=./src/schema/client.graphql --schema=../../schema/server.graphql --queries=\"src/**/*.js\" --target=flow --addTypename --passthroughCustomScalars --customScalarsPrefix=GraphQL --useFlowReadOnlyTypes
// @flow

declare type GraphQLUpload = File | Blob;
mike-marcacci commented 6 years ago

(Didn't mean to close; hit the wrong button.)

mike-marcacci commented 6 years ago

OK, I see in your title that you're using graphql-binding. It looks like this is a limitation of their generator, so I am going to close this here. They will likely need to implement better support for custom scalars on their end to get correct typing.

thanatchakromsang commented 6 years ago

@mike-marcacci Thanks for clearing that up for me :)

thanatchakromsang commented 6 years ago

I Fix this issue by modifying TypescriptGenerator in Graphql-binding libs to include custom scalar Mapping Thanks to your input!