graphql-engine/server/src-lib/Hasura/GraphQL
Auke Booij 7547786b2b Build introspection Schema ad-hoc at parsing time
In order to respond to GraphQL queries that make use of the introspection fields `__type` or `__schema`, we need two things:
- an overview of the relevant GraphQL type information, stored in a `Schema` object, and
- to have included the `__type` and `__schema` fields in the `query_root` that we generate.

It used to be necessary to do the above items in that order, since the `__type` and `__schema` fields (i.e. the respective `FieldParser`s) were generated _from_ a `Schema` object.

Thanks to recent refactorings in `Hasura.GraphQL.Schema.Introspect` (see hasura/graphql-engine-mono#2835 or hasura/graphql-engine@5760d9289c), the introspection fields _themselves_ are now `Schema`-agnostic, and simply return a function that takes a `Schema` object after parsing. For instance, the type of `schema`, corresponding to the `__schema` field, has literally changed as follows:
```diff
-schema :: MonadParse n => Schema -> FieldParser n (          J.Value)
+schema :: MonadParse n =>           FieldParser n (Schema -> J.Value)
 ```

This means that the introspection fields can be included in the GraphQL schema *before* we have generated a `Schema` object. In particular, rather than the current architecture of generating `Schema` at startup time for every role, we can instead generate `Schema` ad-hoc at query parsing time, only for those queries that make use of the introspection fields. This avoids us storing a `Schema` for every role for the lifetime of the server.

However: this introduces a functional change, as the code that generates the `Schema` object, and in particular the `accumulateTypeDefinitions` method, also does certain correctness checks, to prevent exposing a spec-incompliant GraphQL schema. If these correctness checks are being done at parsing time rather than startup time, then we catch certain errors only later on. For this reason, this PR adds an explicit run of this type accumulation at startup time. For efficiency reasons, and since this correctness check is not essential for correct operation of HGE, this is done for the admin role only.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3231
GitOrigin-RevId: 23701c548b785929b28667025436b6ce60bfe1cd
2022-02-21 20:23:55 +00:00
..
Execute Updates cabal freeze file 2022-02-18 05:32:08 +00:00
Parser Build introspection Schema ad-hoc at parsing time 2022-02-21 20:23:55 +00:00
Schema Build introspection Schema ad-hoc at parsing time 2022-02-21 20:23:55 +00:00
Transport Derive a few Semigroup+Monoid instances 2022-02-18 14:58:04 +00:00
Analyse.hs Fixed GQL aliases not being respected in the OpenAPI schema 2022-01-27 05:55:55 +00:00
Context.hs Source typename customization (close graphql-engine#6974) 2021-10-29 14:43:14 +00:00
Execute.hs server, pro: add support for per-role allowlists 2022-02-08 16:54:49 +00:00
Explain.hs Source typename customization (close graphql-engine#6974) 2021-10-29 14:43:14 +00:00
Logging.hs Source typename customization (close graphql-engine#6974) 2021-10-29 14:43:14 +00:00
Namespace.hs Refactor type name customization 2021-11-30 09:52:53 +00:00
ParameterizedQueryHash.hs Prevent uses of unsafeMkName whenever possible. 2022-01-27 15:13:37 +00:00
Parser.hs Build introspection Schema ad-hoc at parsing time 2022-02-21 20:23:55 +00:00
RemoteServer.hs server: validate REST endpoint queries after metadata change 2022-02-08 04:47:52 +00:00
Schema.hs Build introspection Schema ad-hoc at parsing time 2022-02-21 20:23:55 +00:00