Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload scalar support for the schema wrapping #2795

Closed
mikeconley12 opened this issue Apr 2, 2021 · 5 comments
Closed

Upload scalar support for the schema wrapping #2795

mikeconley12 opened this issue Apr 2, 2021 · 5 comments

Comments

@mikeconley12
Copy link

Is your feature request related to a problem? Please describe.

I'm using @graphql-tools/[email protected] package with [email protected]. And I have code similar to this:

const wrappedSchema = wrapSchema({
  schema,
  transforms: [
    new RenameTypes(name => {
      // ...
    }),
  ],
})

The schema has the Upload scalar from the graphql-upload package. When I run my code I have the following error: Error: ‘Upload’ scalar serialization unsupported.. The serialize method is called by the wrapSchema function.

Please see the links:

  1. return transformInputValue(type, value, (t, v) => t.serialize(v));

  2. const serializedValue = serializeInputValue(varType, variableValues[varName]);

Describe the solution you'd like

Is it possible to avoid calling the serialize method when using the wrapSchema function? Or is there another solution?

Describe alternatives you've considered

I defined my own version of the Upload scalar:

const GraphQLUpload = new GraphQLScalarType({
  name: 'Upload',
  description: 'The `Upload` scalar type represents a file upload.',
  parseValue: (value: any) => value,
  parseLiteral () {
    throw new Error('‘Upload’ scalar literal unsupported.')
  },
  serialize (value) {
    return value
  },
})

This solved the error, but it doesn't seem safe

Additional context

My Node.js version is v14.16.0 and I'm using Ubuntu 20.04

@ardatan
Copy link
Owner

ardatan commented Apr 3, 2021

@mikeconley12
Copy link
Author

@ardatan thanks for your answer! But is it safe to just return the value from the serialize method? Original GraphQLUpload throws an error in the serialize method

@ardatan
Copy link
Owner

ardatan commented Apr 3, 2021

@mikeconley12 It is passed internally to the subschema so I don't think it is unsafe. @yaacovCR What do you think?

@yaacovCR
Copy link
Collaborator

yaacovCR commented Apr 3, 2021

jaydenseric/graphql-upload#194

@jaydenseric has some valid reasons for not changing the scalar. He suggests a workaround over there for us to avoid “serializing” the scalar using the normal method, which I don’t find terribly appealing.

I think this might relate to a broader graphql discussion about whether there could be a way to mark a scalar (or enum) as only valid for input (or output).

Our present options are to take up his extensions suggestion or just encourage users to use our version of the scalar without the serialize check. Its perfectly safe, you just have to remember on your own to not use the upload scalar as output.

@mikeconley12
Copy link
Author

Thank you for the answers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants