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

feat: plugs and adapters #8

Open
1 of 2 tasks
simonireilly opened this issue Jan 26, 2022 · 1 comment
Open
1 of 2 tasks

feat: plugs and adapters #8

simonireilly opened this issue Jan 26, 2022 · 1 comment

Comments

@simonireilly
Copy link
Owner

simonireilly commented Jan 26, 2022

When need to allow for different request/response formats.

In general, we could have two scenario's:

Adapters

Option 1

We could configure the response adapter like:

const api = compeller(spec, {
  adapter: 'apigateway'
});

const { request, response } = api('/api/v1/line-items/{id}', 'get')

Option 2

Design an interface.

If we will hand off the interfaces of statusCode, body?, headers? then we can allow for an adapter to be written like:

const responder = (
  statusCode: number, 
  body: Record<string, unknown> = {}, 
  headers: Record<string, unknown> = {}
) => ({
  statusCode,
  body: JSON.stringify(body),
  headers
})

const api = compeller(spec, {
  responder,
});

const { request, response } = api('/api/v1/line-items/{id}', 'get')
@simonireilly
Copy link
Owner Author

The interface option was added in #27

Its stable enough for now, but types are not propagated out of the responder, and this needs to be improved so that schema types from responder can then we passed on e.g.

const response = responder('200', { name: 'simon'})

return {
  // Currently response is not typed :cry: 
  ...response,
  headers: {
    'x-additional-header': 'not-worth-injection'
  }
}

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