Explicitly remap the supergraph config (#614)

## Description

With #613 merged, it is safe to create an `__globals` subgraph into
which we can sort all supergraph config. This PR gives supergraph
objects a qualified name (using the `__globals` subgraph). Note that
outside of debugging/tracing, this is functionally a no-op: we strip the
subgraph from the objects as soon as we use them, because the global
nature of the config means that this is irrelevant information.

<!--
  Questions to consider answering:
  1. What user-facing changes are being made?
2. What are issues related to this PR? (Consider adding `(close
#<issue-no>)` to the PR title)
  3. What is the conceptual design behind this PR?
  4. How can this PR be tested/verified?
  5. Does the PR have limitations?
  6. Does the PR introduce breaking changes?
-->

## Changelog

### Product

_(Select all products this will be available in)_

- [x] community-edition
- [x] cloud
<!-- product : end : DO NOT REMOVE -->

### Type

<!-- See changelog structure:
https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog
-->

_(Select only one. In case of multiple, choose the most appropriate)_

- [ ] highlight
- [ ] enhancement
- [ ] bugfix
- [x] behaviour-change
- [ ] performance-enhancement
- [ ] security-fix
<!-- type : end : DO NOT REMOVE -->

### Changelog entry

<!--
  - Add a user understandable changelog entry
- Include all details needed to understand the change. Try including
links to docs or issues if relevant
  - For Highlights start with a H4 heading (#### <entry title>)
  - Get the changelog entry reviewed by your team
-->

Metadata config declared under the `supergraph` field will now appear as
part of an `__globals` subgraph in tracing. Note that the field can also
be omitted and the config placed in a user-named subgraph.

<!-- changelog-entry : end : DO NOT REMOVE -->

<!-- changelog : end : DO NOT REMOVE -->

V3_GIT_ORIGIN_REV_ID: 84d2beed98f843df246c8562188cdf7de63643fc
This commit is contained in:
Tom Harding 2024-05-27 20:43:37 +02:00 committed by hasura-bot
parent 9546362b2e
commit 01711c20da
2 changed files with 14 additions and 7 deletions

View File

@ -1,7 +1,9 @@
//! This is where we will resolve graphql configuration
use crate::helpers::types::mk_name;
/// this is where we will resolve graphql configuration
use crate::types::error::{Error, GraphqlConfigError};
use lang_graphql::ast::common as ast;
use open_dds::accessor::QualifiedObject;
use open_dds::graphql_config::{self, OrderByDirection};
use serde::{Deserialize, Serialize};
@ -68,7 +70,7 @@ pub struct GraphqlConfig {
/// that that object is mandatory) throw an error
/// * if the flag is not set, use the fallback object
pub fn resolve(
graphql_configs: &Vec<graphql_config::GraphqlConfig>,
graphql_configs: &Vec<QualifiedObject<graphql_config::GraphqlConfig>>,
flags: &open_dds::flags::Flags,
) -> Result<GraphqlConfig, Error> {
if graphql_configs.is_empty() {
@ -82,7 +84,9 @@ pub fn resolve(
} else {
match graphql_configs.as_slice() {
// There should only be one graphql config in supergraph
[graphql_config] => resolve_graphql_config(graphql_config),
// Because this config can only be defined in once in a supergraph, it doesn't actually
// matter which subgraph defines it: the outcome will be the same.
[graphql_config] => resolve_graphql_config(&graphql_config.object),
_ => Err(Error::GraphqlConfigError {
graphql_config_error: GraphqlConfigError::MultipleGraphqlConfigDefinition,
}),

View File

@ -39,7 +39,7 @@ pub struct MetadataAccessor {
pub command_permissions: Vec<QualifiedObject<permissions::CommandPermissionsV1>>,
pub flags: flags::Flags,
// `graphql_config` is a vector because we want to do some validation depending on the presence of the object
pub graphql_config: Vec<graphql_config::GraphqlConfig>,
pub graphql_config: Vec<QualifiedObject<graphql_config::GraphqlConfig>>,
}
fn load_metadata_objects(
@ -55,8 +55,9 @@ fn load_metadata_objects(
.push(QualifiedObject::new(subgraph, data_connector.upgrade()));
}
OpenDdSubgraphObject::GraphqlConfig(graphql_config) => {
// TODO: we need to map this into a "virtual subgraph"
accessor.graphql_config.push(graphql_config);
accessor
.graphql_config
.push(QualifiedObject::new(subgraph, graphql_config));
}
OpenDdSubgraphObject::ObjectType(object_type) => {
accessor
@ -130,7 +131,9 @@ fn load_metadata_supergraph_object(
) {
match supergraph_object {
OpenDdSupergraphObject::GraphqlConfig(graphql_config) => {
accessor.graphql_config.push(graphql_config);
accessor
.graphql_config
.push(QualifiedObject::new("__globals", graphql_config));
}
}
}