graphql-engine/server/src-lib/Hasura
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
..
Backends server: trivial refactor in postgres insert 2022-02-21 18:22:56 +00:00
Base Updates cabal freeze file 2022-02-18 05:32:08 +00:00
Cache server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Eventing Deploy server documentation to github page in CI 2022-01-31 13:16:29 +00:00
Experimental Role-invariant schema constructors 2022-02-17 08:17:17 +00:00
GraphQL Build introspection Schema ad-hoc at parsing time 2022-02-21 20:23:55 +00:00
Incremental distinct_on for BigQuery 2022-01-17 10:02:17 +00:00
Metadata server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
RQL Metadata code cleanups 2022-02-18 12:47:56 +00:00
Server server: assorted minor clean-up around HTTP managers 2022-02-16 07:09:47 +00:00
SQL Experimental backend adapter 2021-12-22 00:11:28 +00:00
App.hs Metadata code cleanups 2022-02-18 12:47:56 +00:00
EncJSON.hs server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
GC.hs server: add explicit export lists in OSS server and enforce with warning 2021-11-04 16:09:38 +00:00
HTTP.hs Add default User-Agent header for Action requests 2022-01-31 06:50:13 +00:00
Incremental.hs server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Logging.hs server: log DB locking queries during source catalog migration 2021-11-09 14:22:44 +00:00
Prelude.hs Updates cabal freeze file 2022-02-18 05:32:08 +00:00
QueryTags.hs server: add explicit export lists in OSS server and enforce with warning 2021-11-04 16:09:38 +00:00
Session.hs Prevent uses of unsafeMkName whenever possible. 2022-01-27 15:13:37 +00:00
Tracing.hs Remove Unique from Definition 2021-12-01 16:21:35 +00:00