Skip to content

Write a guide about using JS to perform data transformation #152

Closed
@tusharmath

Description

@tusharmath

Update the http-filters.md with an example of modifying incoming request data.

schema  {
  query: Query
  mutation: Mutation
}

type Mutation {
  createUser(input: InputUser): UserCreated @http(
    method: POST, 
    path: "/users", 
    query: [{key: "user", value: "{{args.input}}"}] # pass input as an argument
}

input InputUser {
  name: String
  age: Int
}
function onRequest({request}) {
   const user = JSON.parse(decodeURIComponent(request.uri.query.user))
   request.uri.query = {}
   request.body = {
      userName: user.name,
      userAge: user.age
   }
   return {request}
}

Something on the above lines.

IMPORTANT: Make sure you try the final configuration and that it works.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions