Skip to content

Apollo gateway - file upload "missing operations" error on micro-service !!  #54

@tkssharma

Description

@tkssharma

always please provide examples so that devs don't have to struggle when they use some external 3rd party library

First of all thanks for providing this solution
I am a bit stuck with this solution

I saw this Blog https://medium.com/profusion-engineering/file-uploads-graphql-and-apollo-federation-c5a878707f4c the tried this solution but it does not work

I have nest js apollo federation gateway and microservices to support file upload, my use case is the same as mentioned in this blog
buildService: ({ url }) => new FileUploadDataSource({ url, useChunkedTransfer: true }),
My gateway

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloGatewayDriverConfig>({
      server: {
        context: handleAuth,
      },
      driver: ApolloGatewayDriver,
      gateway: {
        buildService: ({ url }) => new FileUploadDataSource({ url, useChunkedTransfer: true }),
        /* buildService: ({ name, url }) => {
          return new RemoteGraphQLDataSource({
            url,
            willSendRequest({ request, context }: any) {
              request.http.headers.set('userId', context.userId);
              // for now pass authorization also
              request.http.headers.set('authorization', context.authorization);
              request.http.headers.set('permissions', context.permissions);
            },
          });
        }, */
        supergraphSdl: new IntrospectAndCompose({
          subgraphs: [
            { name: 'User', url: 'http://localhost:5006/graphql' },
            { name: 'Home', url: 'http://localhost:5003/graphql' },
            { name: 'Booking', url: 'http://localhost:5004/graphql' },
          ],
        }),
      },
    }),
  ],
})

earlier I was trying this based on some existing issues on this repo

 gateway: {
        buildService: ({ url }) =>
          new FileUploadDataSource({
            url,
            useChunkedTransfer: true,
            willSendRequest({ request, context }: any) {
              if (context.req) {
                const { cookie, authorization, referer, as, userId, permissions } = context.req.headers;

                request.http.headers.set('userId', userId);
                // for now pass authorization also
                request.http.headers.set('authorization', authorization);
                request.http.headers.set('permissions', permissions);
              }
            },
          }),
        supergraphSdl: new IntrospectAndCompose({
          subgraphs: [
            { name: 'User', url: 'http://localhost:5006/graphql' },
            { name: 'Home', url: 'http://localhost:5003/graphql' },
            { name: 'Booking', url: 'http://localhost:5004/graphql' },
          ],
        }),
      },

This is my curl request, i have created this curl request from the example app you guys have shared

curl 'http://localhost:5002/graphql' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarydTXvKTxEAVztL3Cl' \
  -H 'Origin: http://localhost:3008' \
  -H 'Referer: http://localhost:3008/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36' \
  -H 'accept: */*' \
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data-raw $'------WebKitFormBoundarydTXvKTxEAVztL3Cl\r\nContent-Disposition: form-data; name="operations"\r\n\r\n{"operationName":"uploadHomePhoto","variables":{"file":null},"query":"mutation uploadHomePhoto($file: Upload\u0021) {\\n  uploadHomePhoto(file: $file) {\\n    id\\n    __typename\\n  }\\n}"}\r\n------WebKitFormBoundarydTXvKTxEAVztL3Cl\r\nContent-Disposition: form-data; name="map"\r\n\r\n{"1":["variables.file"]}\r\n------WebKitFormBoundarydTXvKTxEAVztL3Cl\r\nContent-Disposition: form-data; name="1"; filename="qwdeqd.txt"\r\nContent-Type: text/plain\r\n\r\nqwedqdeq\r\n------WebKitFormBoundarydTXvKTxEAVztL3Cl--\r\n' \
  --compressed

Github Example Client-side
https://github.com/jaydenseric/apollo-upload-examples

at the microservices end I am getting the same always

{"correlationId":"e4464af9-0af4-472d-882f-82de9034d7aa","level":"error","message":"[Fri May 27 15:32:43 2022] [error] Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec)."}
{"correlationId":"e4464af9-0af4-472d-882f-82de9034d7aa","level":"error","message":"[Fri May 27 15:32:43 2022] [error] Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec)."}
{"correlationId":"e4464af9-0af4-472d-882f-82de9034d7aa","level":"error","message":"[Fri May 27 15:32:44 2022] [error] Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec)."}
{"correlationId":"e4464af9-0af4-472d-882f-82de9034d7aa","level":"error","message":"[Fri May 27 15:32:44 2022] [error] Missing multipart field ‘operations’ (https://github.com/jaydenseric/graphql-multipart-request-spec)."}

Please let me know your inputs on this.

Thx,

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions