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

Support extending a consumer method using the definition of another #151

Closed
prkumar opened this issue Mar 19, 2019 · 0 comments · Fixed by #159
Closed

Support extending a consumer method using the definition of another #151

prkumar opened this issue Mar 19, 2019 · 0 comments · Fixed by #159
Assignees
Milestone

Comments

@prkumar
Copy link
Owner

prkumar commented Mar 19, 2019

Is your feature request related to a problem? Please describe.
This issue is spun out of a discussion on Gitter with @liiight:

@prkumar i have a question. I wanna do something like this:

class Lestrade(FlapiBase):
    @lestrade_error
    @json
    @post('lestrade/graphql')
    def graphql(self, **body: Body):
        pass

    @returns.json(member=('data', 'incidents'))
    def get_incident(self, **body) -> Incident:
        return self.graphql(**body)

    @returns.json(member=('data', 'updateIncident'))
    def update_incident(self, **body: Body) -> UpdateCommandResponse:
        return self.graphql(**body)

Essentially, we want two separate "child" consumer methods that "inherit" details from the graphql consumer method.

Describe the solution you'd like

In summary, we can use the graphql consumer method as a decorator on subsequent methods in the class definition so that they can inherit and enhance the request definition, separately. (This should be actually pretty simple to implement.)

class Lestrade(FlapiBase):
    @lestrade_error
    @json
    @post('lestrade/graphql')
    def graphql(self, **body: Body):
        pass

    @returns.json(member=('data', 'incidents'))
    @graphql
    def get_incident(self, **body) -> Incident:
        pass

    @returns.json(member=('data', 'updateIncident'))
    @graphql
    def update_incident(self, **body) -> UpdateCommandResponse:
        pass

Notably, the decorated methods need to have the same argument signature as the graphql method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant