-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Omit types, queries and mutations in production #2368
Comments
It is unclear to me what you are actually asking. Please reformulate your issue in terms of an actual problem and reflect that in the title. |
I guess he wanted to expose some fields/queries only for local tests. class DebugDirective extends BaseDirective implements FieldMiddleware
{
private bool $debug;
public function __construct(Repository $config)
{
$this->debug = $config->get('app.debug');
}
public static function definition(): string
{
return <<<GRAPHQL
"""
Limit field access to debug server
"""
directive @debug on FIELD_DEFINITION
GRAPHQL;
}
public function handleField(FieldValue $fieldValue, Closure $next): FieldValue
{
$originalResolver = $fieldValue->getResolver();
return $next(
$fieldValue->setResolver(
function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($originalResolver) {
if(!$this->debug)
return null;
return $originalResolver($root, $args, $context, $resolveInfo);
}
)
);
}
} |
@k0ka yeah, that's almost what I had in mind 😊 I actually even thought about hiding types or fields completely if that's possible? |
I think the issue title and description are insufficiently descriptive of what the intent is. Please update them. |
@env
directive
Removing fields from AST will be a little harder, but I can do it. @spawnia do you think this issue make sense? |
Why not use different location of the schema for specific env?
Only one pitfall here - it is not possible to add directives via |
I think we can widen the scope of this issue even further and make it about the conditional inclusion/exclusion of any schema element. For example, I could see this being useful for any field, not just those on the root types - as well as arguments, enum values, etc. Depending on the environment (via
Clients already have access to a feature that allows conditional inclusion or exclusion of fields controlled through variables via the client directives We could have a simple way for the most common use case of depending on the environment, perhaps like this: For the most complex use cases, we could allow the user to define a function that will be called to determine inclusion: |
@spawnia, performance can be a problem - eg to hide Type, all types/fields/arguments should be iterated, for big schema it can be slow + schema cache seems will not help here. |
I guess hiding must be done during schema creation (via |
What problem does this feature proposal attempt to solve?
Sometimes it's helpful to have certain queries or types in development that are not supposed to be in production. Though we can handle it via field middleware, they will still be visible in production. It would be even better if we could remove queries or types completely depending on the environment or other flags.
Which possible solutions should be considered?
I think something like
@env( name: "local" )
could be helpful to make queries, manipulations and types only available in certain environments.The text was updated successfully, but these errors were encountered: