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

Documentation not clear about uploading file #1403

Open
thedarkknight197 opened this issue Jan 29, 2024 · 1 comment
Open

Documentation not clear about uploading file #1403

thedarkknight197 opened this issue Jan 29, 2024 · 1 comment

Comments

@thedarkknight197
Copy link

thedarkknight197 commented Jan 29, 2024

I need upload file using graphql_mutation. I am also using dio package on my app.

https://github.com/zino-hofmann/graphql-flutter/blob/main/packages/graphql/README.md#graphql-upload

How can i put inside variable a file? I tried with file directly and not work.

I tried also with MultipartFile but nothing:

final result = runMutation({
  "content": text,
  "chatroomId": chatRoomId,
  "attachment": viewModel.attachment.isFileSet()
      ? await MultipartFile.fromFile(
          viewModel.attachment.file!.path,
          filename: viewModel.attachment.file!.path
              .split("/")
              .last)
      : null
});

The reuqest not arrive to my server.

Using talen api request to my graphql endpoint with

{
  "query":"mutation ($chatroomId: Float!, $content: String, $attachment: Upload ) {\n          sendMessage (\n              chatroomId: $chatroomId,\n              content: $content\n, attachment: $attachment\n          ) {\n              attachment {\n                  id\n                  path\n              }\n              chatRoomId\n              content\n              createdAt\n              id\n              userId\n          }\n        }",
  "variables": {
    "chatroomId":2,
    "content": "ciao",
    "attachment": ""
  }
}

the call was blocked by Upload validator, but it arrive...

So i need explaination about how send file using your library to my server.

Thank you for your support

(without attachment request work)

@thedarkknight197
Copy link
Author

thedarkknight197 commented Jan 30, 2024

Now I did some changes the body arrive, but i have a new issue:

[Nest] 31308  - 30/01/2024, 12:46:47   ERROR [ExceptionsHandler] Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec).
BadRequestError: Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec)

the body that arrive to my backend is:

 body: {
    operationName: null,
    variables: { content: '', chatroomId: 2, attachment: [Upload] },
    query: 'mutation($chatroomId: Float!, $content: String, $attachment: Upload) {\n' +
      '  __typename\n' +
      '  sendMessage(chatroomId: $chatroomId, content: $content, attachment: $attachment) {\n' +
      '    __typename\n' +
      '    attachment {\n' +
      '      __typename\n' +
      '      id\n' +
      '      path\n' +
      '    }\n' +
      '    chatRoomId\n' +
      '    content\n' +
      '    createdAt\n' +
      '    id\n' +
      '    userId\n' +
      '  }\n' +
      '}'
  },

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

1 participant