HriBB / graphql-server-express-upload

Graphql Server Express file upload middleware
MIT License
41 stars 5 forks source link

Export UploadedFile scalar resolver #9

Open jaydenseric opened 7 years ago

jaydenseric commented 7 years ago

Step 3 in the instructions, "Add UploadedFile resolver" is too hard to follow.

Pasting the example code into a typical Apollo resolvers.js file wont work because Kind is undefined. Where does that come from, how do you import it? And what is this ast parameter?

This looks pretty boilerplate, why not export the scalar resolver for easy setup?

Something like:

import {UploadedFileResolver} from 'graphql-server-express-upload'

export default {
  UploadedFile: UploadedFileResolver,
  Query: { ... },
  Mutation: {  ... }
}

In the meantime, I can't work out how to get the resolver to work so any clarification would be super helpful.

jaydenseric commented 7 years ago

I got this working by dropping in taion/graphql-type-json. The name is JSON, when ideally it would be UploadedFile, but it seems to be working ok.

import GraphQLJSON from 'graphql-type-json'
export default {
  UploadedFile: GraphQLJSON,
  Query: { ... },
  Mutation: {  ... }
}
HriBB commented 7 years ago

@jaydenseric I agree. Do you want to make a PR?

jaydenseric commented 7 years ago

Perhaps, I am in the middle of some epic refactoring but might be in a place to look at it sometime in the next few days.

The importable resolver might be better placed in HriBB/apollo-upload-network-interface so it does not have to be duplicated for future non-express middleware. Thoughts?

HriBB commented 7 years ago

Yeah I am very busy ATM as well ... will try to update all packages in a batch sometimes soon.

I think that scalar should be a part of the server package(s), because it is not needed on the client. Or it could be a part of some external package or even its own package. I was thinking about using lerna for package management and typescript. Check out this issue

jaydenseric commented 7 years ago

A benefit to keeping it here is the graphql dependency; it already exists here but not yet in apollo-upload-network-interface.

I for one can't stand TypeScript in OSS, it's not real JavaScript and it makes contributing or even understanding the source difficult. A lot of traffic seems to be about fiddling around with types.

vladinator1000 commented 7 years ago

I would love to find out more about this. I've been trying to upload a file for a couple of weeks but no luck.

jaydenseric commented 7 years ago

@savovs If you're still stuck, you might find apollo-upload-server a little easier to get up and running – you don't have to set up a custom scalar or Multer.