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

[IDEA] farrow instrospect instrospect the api since it has already known args type and response type #22

Open
xialvjun opened this issue Jan 8, 2021 · 1 comment

Comments

@xialvjun
Copy link

xialvjun commented Jan 8, 2021

http.match({
  url: '/product/<id:number>?<a:number>&<b:string>&<c:boolean>',
  method: 'POST',
  body: {
    a: Number,
    b: String,
    c: Boolean,
  },
  headers: {
    a: Number,
    b: String,
    c: Boolean,
  },
  cookies: {
    a: Number,
    b: String,
    c: Boolean,
  },
}).use(async (req, next) => {
  return Response.json({ name: 'xialvjun', age: 29 });
})

then use typescript compiler api, farrow instrospect generate json file:

{
  apis: [{
    url: '/product/<id:number>?<a:number>&<b:string>&<c:boolean>',
    method: 'POST',
    body: {
      a: 'number',
      b: 'string',
      c: 'boolean',
    },
    headers: {
      a: 'number',
      b: 'string',
      c: 'boolean',
    },
    cookies: {
      a: 'number',
      b: 'string',
      c: 'boolean',
    },
    response: {
      name: 'string',
      age: 'number'
    }
  }],
}

then farrow generate --plugin=fetch generate js client code:

export const productById = (id: number, query: {a:number,b:string,c:boolean}, xxxx): Promise<{name:string,age:number}> => {xxxx}

I know, this is a huge workload.

Eg the match schema body: {a:Number,b:String,c:Boolean} with constructor is naive. yup is much better which can also give you the validated request type.

I just came up with this idea. I don't really need it since I use graphql.

So I'm not going to contribute on this, I'm trying to translate apollo-koa-server to apollo-farrow-server. I know there is 'farrow-graphql', but 'apollo' and 'graphql-code-generator' works grate.

@Lucifier129
Copy link
Collaborator

apollo-farrow-server seems good:)

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

2 participants