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: create interface for responder so responder types take presidence over default types #27

Merged
merged 4 commits into from
Jan 28, 2022

Conversation

simonireilly
Copy link
Owner

@simonireilly simonireilly commented Jan 28, 2022

This first feature abstracts responders so that the response type can be composed functionally.

The benefit of this is that we can retain the typed interface:

response(statusCode, body)

At this time the body is permitted to be any type, while statusCode must extend string, symbol, or number.

Composing a responder can be done functionally:

const customerCompeller = compeller(OpenAPISpecification, {
  responder: (statusCode, body) => {
    return typeof statusCode === 'string'
      ? {
          statusCode: parseInt(statusCode),
          body: JSON.stringify(body),
        }
      : {
          statusCode,
          body: JSON.stringify(body),
        };
  },
});

Enabling injection.

@simonireilly simonireilly changed the title WIP: Create interface for responder so responder types take presidence over default types feat: create interface for responder so responder types take presidence over default types Jan 28, 2022
@simonireilly simonireilly merged commit 65a8af0 into main Jan 28, 2022
@simonireilly simonireilly deleted the feat/responders-need-better-typing branch January 28, 2022 11:32
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

Successfully merging this pull request may close these issues.

1 participant