SOFA icon indicating copy to clipboard operation
SOFA copied to clipboard

After SOFA v0.12.0 upgrade, "Variable X of required type String! not provided" errors for multiple mutations

Open kleydon opened this issue 3 years ago • 7 comments

After upgrading from Sofa v0.11.2 to v0.12.0, parameters provided in the body of my REST requests are no longer found/recognized by SOFA's auto-generated REST API. If I switch back to SOFA v0.11.2, my requests work again.

For example, my login request http://localhost:2020/auto-rest/auth-login-by-phone, made with the body: { "phone": "+12676146833" } yields the error:

Variable "$phone" of required type "String!" was not provided.

It doesn't matter whether I'm running on localhost on a MacBook (http) or on gcloud run (https); it doesn't matter whether I make the request via Postman or via a Swagger REST UI - the error is consistently the same. The error occurs in response to multiple requests with body parameters (that correspond to mutations).

When I examine the request (above), as received by the context function provided to my useSofa() function (below), the request DOES (at this point) contain the expected string value for phone; { "phone": "+12676146833" }

  const openApi = OpenAPI({ schema })
  app.use(
    autoRestApiBaseRoute,
    useSofa({
      schema,
      basePath: autoRestApiBaseRoute,
      context: (request: any) => {
        return {
          ...request,
          prisma,
        }
      },
      depthLimit: 2,
      onRoute(info:any) {
        openApi.addRoute(info, {
          basePath: autoRestApiBaseRoute
        })
      }
    })
  )
  app.use(autoRestApiDocsRoute, swaggerUi.serve, swaggerUi.setup(openApi.get()))
}

Some additional context:

The relevant portion of my GraphQL Schema:

...
type Mutation {
  ...
  authLoginByPhone(phone: String!): StringPayload!
  ...
}  
...

My authLoginByEmail() resolver, created using type-graphql:

  @Mutation(returns => StringPayload)
  async authLoginByEmail(
    @Ctx() ctx: Context,
    @Info() info: GraphQLResolveInfo,
    @Arg('email') email: string,  //email address
  ): Promise<StringPayload> {
    ilog('authLoginByEmail():')
    const session = ctx.request.session
    const result = await logInByEmail({ email, session })
    return result
  } 

I've looked through the release notes for v0.12.0, and don't yet see anything that would need to change in my code, between v0.11.2 and v.0.12.0 - but perhaps I'm wrong? If you have any recommendations - or know how I could debug further "downstream" than the body of the context function, (mentioned above) - I'd love to know about it. It does seem like this is a bug though, from what I can see so far.

kleydon avatar Sep 24 '22 01:09 kleydon

Please share a minimal and clear reproduction on CodeSandbox or StackBlitz

ardatan avatar Sep 24 '22 02:09 ardatan

Hi @ardatan,

I've just posted a minimal and clear reproduction on GitHub here, and a slightly modified version on CodeSandbox here. The README describes how to reproduce the issue.

If any additional info would be useful, please let me know.

kleydon avatar Sep 24 '22 22:09 kleydon

Yes, I am also facing this issue. made sure the body-parser is working. but still the same issue. it's working with only url params. for me, I was using v0.15.0.

MejanH avatar Nov 06 '22 16:11 MejanH

I'm facing the same issue, too. I have tried it with version 0.15.1.

DanielHefti avatar Dec 05 '22 10:12 DanielHefti

Same issue here. Seems like POST routes doesn't accept Content-Type: application/json as a header, only Content-Type: text/plain

mhaagens avatar Feb 16 '23 14:02 mhaagens

I've run into this issue while integrating SOFA with Nest. Disabling bodyParser on app instance actually solved the problem.

oleg-prikhodko avatar Mar 16 '23 17:03 oleg-prikhodko