Skip to content

Conditional uses of arguments #199

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

Closed
Naoto-Ida opened this issue Jul 29, 2016 · 4 comments
Closed

Conditional uses of arguments #199

Naoto-Ida opened this issue Jul 29, 2016 · 4 comments

Comments

@Naoto-Ida
Copy link

Naoto-Ida commented Jul 29, 2016

Is there any support for conditional uses of arguments, i.e. when you have at and by,
but you can only accept an argument one at a time. Or should we write the code ourselves to check if both arguments are available in throw an GraphQLError?

GraphQLObjectType({
    name: 'Event',
    type: new GraphQLList(EventType),
    args: {
        at: {
            type: CoordinateType,
            description: 'Coordinates of the event's venue (approximate).'
        },
        by: {
            type: CoordinateType,
            description: 'Coordinates of the event's venue (exact).'
        },
    }
})

@JeSuisNikhil
Copy link

Can't say I speak with authority but I think the answer is no. Your other options are to have two fields names EventAt(CoordinateType) & EventBy(CoordinateType) or an additional boolean argument to field Event(c: CoordinateType, isExact: Boolean)

Can't say I like either of those options either 😄

@Naoto-Ida
Copy link
Author

@IamCornholio Roger that. Your option may be very close to what I need now. Thanks for the advice 😀

@sorenbs
Copy link

sorenbs commented Dec 2, 2016

Cases like this is why some are arguing for union input types: graphql/graphql-js#207 That proposal has some issues, but this is certainly an area where GraphQL could improve.

@leebyron
Copy link
Collaborator

leebyron commented May 1, 2018

Closing this aging issue. Custom code would be necessary to enforce this sort of argument usage.

@leebyron leebyron closed this as completed May 1, 2018
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

4 participants