GraphQLBundle icon indicating copy to clipboard operation
GraphQLBundle copied to clipboard

Inject schema extensions to SchemaBuilder via DI

Open videni opened this issue 6 years ago • 1 comments

the ValidatorExtension is binding to SchemaBuilder statically, can we Inject schema extensions to SchemaBuilder via DI?

videni avatar Nov 01 '19 04:11 videni

I see, currently we can add custom schema extension via the Events::PRE_EXECUTOR event

   private function preExecute(
        Schema $schema,
        ?string $requestString,
        \ArrayObject $contextValue,
        $rootValue = null,
        ?array $variableValue = null,
        ?string $operationName = null
    ): ExecutorArgumentsEvent {
        $this->dispatcher->dispatch(
            new ExecutorContextEvent($contextValue),
            Events::EXECUTOR_CONTEXT
        );

        return $this->dispatcher->dispatch(
            ExecutorArgumentsEvent::create($schema, $requestString, $contextValue, $rootValue, $variableValue, $operationName),
            Events::PRE_EXECUTOR
        );
    }

@mcg-web , the schema name is absent in ExecutorArgumentsEvent, can we also pass schema name to it ? or keep the schemName in the initial contextValue.

 $executorArgumentsEvent = $this->preExecute(
            $this->getSchema($schemaName),
            $request[ParserInterface::PARAM_QUERY] ?? null,
            new \ArrayObject(['schema' => $schemaName]),
            $rootValue,
            $request[ParserInterface::PARAM_VARIABLES],
            $request[ParserInterface::PARAM_OPERATION_NAME] ?? null
        );

I think the first option is better, in nature, it should be in the event.

videni avatar Nov 01 '19 04:11 videni