-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Shorthand for type modifiers #617
Comments
That's some trickery right there. I don't know enough about the GraphQL DSL, I just hope there isn't more to it the wrapper then wouldn't support, can't say. I probably won't use it because I made it a happen to use type constant names to reference the types, something like: Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type(ClientType::TYPE)))); and then I can click on With your approach I would start to do string concatenation: GraphQL::parse('[' . ClientType::TYPE . '!]!') I value introspection more than fewer characters and unfortunately the readability isn't really given anymore. Although I'm not disliking the DSL, I always found it difficult when lots of Also such an approach (though I understand you just dumped your macro there for PoC) doesn't really parse so if there's a bug in the DSL, outcome but still work or not, who knows, but yield to a wrong DSL what if I miss to close the I.e. looks like tiny new feature but also adds more complexity to maintain, so we've to weight that against the benefits. PS: and I just realized how much I like the long-winded approach, it's just so more readable. But then, I've been working with it for years so I'm definitely biased 😄 |
@mfn the missing >>> GraphQL::parse('String]')
Rebing/GraphQL/Exception/TypeNotFound with message 'Type String] not found.'
>>> GraphQL::parse('!String')
Rebing/GraphQL/Exception/TypeNotFound with message 'Type !String not found.'
>>> GraphQL::parse('[String')
Rebing/GraphQL/Exception/TypeNotFound with message 'Type [String not found.'
>>> GraphQL::parse('[String!')
Rebing/GraphQL/Exception/TypeNotFound with message 'Type [String not found.'
>>> GraphQL::parse('[]')
Rebing/GraphQL/Exception/TypeNotFound with message 'Type [] not found.'
>>> GraphQL::parse('!')
Rebing/GraphQL/Exception/TypeNotFound with message 'Type not found.' These errors would be as obvious as any other incorrect type name, I think this is a nice solution in that regard, I gave it some thought to make sure it's reasonable. As far as I've read Your The main reason I want this functionality is because I want to reduce the complexity involved in defining complex type modifier combos, and make it clearer what the resulting end-user queries will have to look like – the project I'm working on has lots of error cases where a user can omit arguments or pass nulls causing resolution errors – a terse DSL for defining nonNull combos makes communicating and spotting incorrect argument definitions a little easier. -- Also RE your |
Yes, after about 50 queries and 100 types it started to get annoying to "navigate" the code base and so we just made it a convention: class AttachmentType extends BaseType
{
public const TYPE = 'Attachment';
/** @var string[] */
protected $attributes = [
'name' => self::TYPE,
]; and then of course the constant |
@mfn the more I use this macro the more I like it 🤭️ (fyi I am at 120 queries, 80 types) – the ability to quick glance these definitions is valuable, and I don't use ctags or similar anyway 🙊 The verbosity of applying nonNull definitions so far has lead the project I've inherited down a path that has resulted in brittle behaviours – most queries enforce requirement via Laravel rules or resolver logic, or not at all, meaning there's no schema/introspection visibility of those requirements, and in many places, omitting an argument, passing a I think we could do a better job of pushing developers towards favouring GraphQL modifiers over Laravel validation rules for requirement and nullability, and a terser way to define argument types in that way is a step towards that. If the library requires |
I always thought it was a basic design mistake they made nullable default 🤷♀️ It's the one thing PHP got so much right with it's types, in comparison to e.g. Java 😏 |
Fixed with #621 |
Yeah it's caused me a lot of issues that "optional by default" alone wouldn't have caused given you can supply a I am currently using the pattern of supplying a |
Argument types with modifiers can get a bit verbose e.g. if you want a non null list of non nulls:
I've written a macro that adds support for variable type syntax
GraphQL::parse('[MyInput!]!')
:Also adds support for the standard types e.g.
GraphQL::parse('[String!]')
.The
GraphQL::type()
method already accepts a string, I'd consider adding in there.The text was updated successfully, but these errors were encountered: