You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GlobalVariables is a service passed to every generated GraphQL type. It contains all necessary services and references to other types to configure a GraphQL schema. The name GlobalVariables doesn't really explain anything, I suggest to rename it to better reflect it's purpose.
Suggested name: GraphQLServices
Other possible names: SchemaServices, TypeServices, TypeHelper
2. Move ConfigProcessor into GlobalVariables
Every generated type also gets ConfigProcessor object, which is only used in types and nowhere else. If GlobalVariables contains all necessary services for types, then why not also moving the ConfigProcessor inside it?
$services->mutation("get_users", $args, $value) // variable-length argument list
The signature is also changed to be simpler.
4. Use QueryResolver instead of ResolverResolver
We have 2 expression resolver functions: resolver and mutation. If we are using the word mutation, which is a type
of resolver, then I suggest renaming resolver into query to be more like a counterpart of mutation. It will also
make more sense in YAML configs (no tautology resolve: resolver):
The signature is also more simple now (no arrays as suggested in section 3)
It also includes renaming of the ResolverInterface into QueryInterface
5. Make the expression prefix configurable
In my projects I would like to be able to change the expression trigger. The symbols @= at the beginning of a string
require it to be wrapped in quotes. If I change the trigger symbol to $ for example, then I don't have to wrap
expression strings into quotes:
Before:
resolve: '@=mutation("get_users", args, info)'
After:
resolve: $mutation("get_users", args, info)
Or just use @:
resolve: '@mutation("get_users", args, info)'
A better alternative to GraphQLServices would be of course a separate injection of only required services into each of generated types, instead of injecting a container, which is considered a bad practice, but I am currently not sure how to implement it.
The text was updated successfully, but these errors were encountered:
Also to note, currently injecting stuff at runtime via globalVariable requires you to have services set public. For constructor injection you would need to make all the generated types available as services adjusting container definitions in compiler pass. I can't quite figure out the implication doing so... But if it would be possible it would be great...
Agree on other points (smiles ResolverResolver made me grin a bit once)
Some of the proposed changes are BC-break.
List of proposed changes
1. Rename
GlobalVariables
class.GlobalVariables
is a service passed to every generated GraphQL type. It contains all necessary services and references to other types to configure a GraphQL schema. The nameGlobalVariables
doesn't really explain anything, I suggest to rename it to better reflect it's purpose.Suggested name:
GraphQLServices
Other possible names:
SchemaServices
,TypeServices
,TypeHelper
2. Move
ConfigProcessor
intoGlobalVariables
Every generated type also gets
ConfigProcessor
object, which is only used in types and nowhere else. IfGlobalVariables
contains all necessary services for types, then why not also moving theConfigProcessor
inside it?Before:
After:
3. Add shortcuts into
GraphQLServices
Add methods for frequently used services, like
typeResolver
,resolverResolver
andmutationResolver
Before:
After:
In this case arrow functions can be used:
So now instead of this:
we have this
The signature is also changed to be simpler.
4. Use
QueryResolver
instead ofResolverResolver
We have 2 expression resolver functions:
resolver
andmutation
. If we are using the wordmutation
, which is a typeof resolver, then I suggest renaming
resolver
intoquery
to be more like a counterpart ofmutation
. It will alsomake more sense in YAML configs (no tautology
resolve: resolver
):Before:
After:
The signature is also more simple now (no arrays as suggested in section 3)
It also includes renaming of the
ResolverInterface
intoQueryInterface
5. Make the expression prefix configurable
In my projects I would like to be able to change the expression trigger. The symbols
@=
at the beginning of a stringrequire it to be wrapped in quotes. If I change the trigger symbol to
$
for example, then I don't have to wrapexpression strings into quotes:
Before:
After:
Or just use
@
:A better alternative to
GraphQLServices
would be of course a separate injection of only required services into each of generated types, instead of injecting a container, which is considered a bad practice, but I am currently not sure how to implement it.The text was updated successfully, but these errors were encountered: