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

Curl example #6

Closed
lunchboxer opened this issue Jan 9, 2018 · 14 comments
Closed

Curl example #6

lunchboxer opened this issue Jan 9, 2018 · 14 comments

Comments

@lunchboxer
Copy link

The readme could be improved by adding an example of usage with CURL. I myself am having difficulty figuring out exactly how it would look.

@jaydenseric
Copy link
Owner

In the meantime, you might find the apollo-upload-server tests to be a handy reference.

@giautm
Copy link

giautm commented Jan 14, 2018

@lunchboxer Here is an example, I copied from Postman. ^_^

curl -X POST \
  http://localhost:3001/graphql \
  -H 'Cache-Control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'operations={"query":"mutation ($files: [Upload!]!) {multipleUpload(files: $files) {id filename encoding mimetype path __typename}}","variables":{}}' \
  -F 'map={"0":["variables.files.0"],"1":["variables.files.1"]}' \
  -F '"0"=@/Users/giautm/Devel/IMG_0636.JPG' \
  -F '"1"=@/Users/giautm/Devel/IMG_0637.JPG'

Ps: Replace files 0, 1 path with your files.

jaydenseric added a commit that referenced this issue Jan 28, 2018
- Examples match those of https://github.com/jaydenseric/apollo-upload-examples.
- Added example cURL requests, fixing #6.
- Added example request payloads.
@jaydenseric
Copy link
Owner

Done! The examples now match those of apollo-upload-examples, and they each display a cURL request.

@gustavomc
Copy link

gustavomc commented Apr 6, 2018

im getting:

Error: Must provide document
  at invariant (/app/node_modules/graphql/jsutils/invariant.js:19:11)
  at Object.validate (/app/node_modules/graphql/validation/validate.js:59:34)
  at doRunQuery (/app/node_modules/apollo-server-core/src/runQuery.ts:137:30)
  at /app/node_modules/apollo-server-core/src/runQuery.ts:70:39
  at <anonymous>
  at process._tickDomainCallback (internal/process/next_tick.js:228:7)

when executing curl

any idea? @jaydenseric

@jaydenseric
Copy link
Owner

@gustavomc No solid ideas, but are you sure apollo-upload-server is setup correctly?

@gohelkiran30
Copy link

I am getting below error with above curl command

curl -X POST \
  http://localhost:3001/graphql \
  -H 'Cache-Control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'operations={"query":"mutation ($files: [Upload!]!) {multipleUpload(files: $files) {id filename encoding mimetype path __typename}}","variables":{}}' \
  -F 'map={"0":["variables.files.0"],"1":["variables.files.1"]}' \
  -F '"0"=@/Users/giautm/Devel/IMG_0636.JPG' \
  -F '"1"=@/Users/giautm/Devel/IMG_0637.JPG'

{"errors":[{"message":"GraphQL Request must include at least one of those two parameters: "query" or "queryId"","category":"request"}]}

@jaydenseric
Copy link
Owner

@gohelkiran30 that might be because the server is not configured to handle multipart requests. Have you setup the apollo-upload-server middleware?

@gohelkiran30
Copy link

I havn't used any middleware, I am firing a request from console using a curl command hence no middleware required.

@jaydenseric
Copy link
Owner

The GraphQL server that you are sending the request to (http://localhost:3001/graphql) needs to support GraphQL multipart requests, typically via middleware. Comments in existing issues in this repo is not the right place to asking such usage questions.

@gohelkiran30
Copy link

ok, I will create a new issue
thanks

@yfyfyfyfyfyf
Copy link

@gustavomc
I'm running into the same issue. Any luck solving this one? Thanks a lot!

@sunapi386
Copy link

sunapi386 commented Nov 21, 2018

@gohelkiran30 @giautm I noticed you both are using "variables":{} in a multipleUpload query. This didn't work for me, I get this error:

file-upload> curl localhost:4000 \
                                 -F operations='{ "query": "mutation ($files: [Upload!]!) { multipleUpload(files: $files) { id } }", "variables": {  } }' \
                                 -F map='{ "0": ["variables.file.0"], "1": ["variables.file.1"] }' \
                                 -F 0=@yarn.lock \
                                 -F 1=@package.json
{"errors":[{"message":"Variable \"$files\" of required type \"[Upload!]!\" was not provided.","locations":[{"line":1,"column":11}]}]}⏎    

and actually in the curl example given, you can remove the variable part for singleUpload and it'll still work

file-upload> curl localhost:4000 \
                                 -F operations='{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { id } }" }' \
                                 -F map='{ "0": ["variables.file"] }' \
                                 -F 0=@yarn.lock
{"data":{"singleUpload":{"id":"TLoQ9s44G"}}}⏎      

but multipleUpload won't

file-upload> curl localhost:4000 \
                                 -F operations='{ "query": "mutation ($files: [Upload!]!) { multipleUpload(files: $files) { id } }" }' \
                                 -F map='{ "0": ["variables.file.0"], "1": ["variables.file.1"] }' \
                                 -F 0=@yarn.lock \
                                 -F 1=@package.json
{"errors":[{"message":"Variable \"$files\" of required type \"[Upload!]!\" was not provided.","locations":[{"line":1,"column":11}]}]}⏎       

@jaydenseric
Copy link
Owner

@sunapi386
Copy link

@jaydenseric my bad, I mistyped variables.file.1 when it should have been variables.files.1

Very subtle error.

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

No branches or pull requests

7 participants