Closed mathroc closed 4 years ago
This can be done with the Symfony command dump schema and composer events post update and post install so you don't need to commit them.
I was probably not very clear I’ll try to explain what I’m trying to do in more details
schema.graphql
: I want to view the diff in the merge request code review, I can generate it with graphql:dump-schema
but I still need to remember it, I don’t think composer events could help me there, git hook might but they need to be configured each time someone clone the repository which is cumbersome. It also helps to pinpoint which commit made api changes (git log api/schema.graphql
).
schema-fragments.json
cannot be generate by graphql:dump-schema
afaict, I generate it like that:
$result = $this->requestExecutor
->execute(null, [
ParserInterface::PARAM_QUERY => <<<GQL
query {
__schema {
types {
kind
name
possibleTypes {
name
}
}
}
}
GQL,
ParserInterface::PARAM_VARIABLES => [],
])
->toArray();
file_put_contents(
"{$this->projectDir}/schema-fragments.json",
\json_encode($result, \JSON_PRETTY_PRINT),
) or die("failed to save {$this->projectDir}/schema-fragments.json");
There’s a js project in the same repo for the frontend, it uses both files (schema.graphql for eslint and graphql auto compelete, and schema-fragments.json is for the apollo client IntrospectionFragmentMatcher
I want to generate this both automatically as soon as graphql-bundle update the generated schema code so that the js project can pickup the changes almost in real time when developing.
I looked a little bit into it. It's not a bad idea and could allow multiple use-cases.
It would only require to inject the eventDispatcher
into the TypeGenerator
and dispatch a CompileEvent
.
@mathroc What about a little PR ?
I’d like to export the schema to schema-fragments.json and schema.graphql files to commit them in the repo so that code review can view a diff of schema.graphql to easily understand how the changes affect the schema (schema-fragments.json is for apollo)
I couldn’t find any event to hook into for that, I tried doing this in a cache warmer, it works but needs is only called when explicitly calling
console cache:clear
not when the cache is updated on a web requestI have a job in CI to check that the schema.graphql is up to date in case someone forgot to call
cache:clear
but it’s annoying to have a pipeline fail because we forgot that, so I was hoping to find a way to do this automaticallydo you think it would be appropriate to dispatch an event allowing that ?