mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-20 23:17:30 +03:00
server/console: add metadata API set_apollo_federation_config
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5294 Co-authored-by: Varun Choudhary <68095256+Varun-Choudhary@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> GitOrigin-RevId: 274d76ff92970ecffa43943125313ba84b07c495
This commit is contained in:
parent
52c1e9b0a8
commit
f6067cb977
@ -6,6 +6,8 @@
|
||||
|
||||
|
||||
- server: add warning log for missing admin secret
|
||||
- server: add metadata API to enable Apollo Federation for a table
|
||||
- console: add console support for Apollo Federation
|
||||
- console: add custom names for streaming subscriptions
|
||||
## v2.10.0-beta.1
|
||||
|
||||
|
@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import Toggle from 'react-toggle';
|
||||
import { useServerConfig } from '@/hooks';
|
||||
import KnowMoreLink from '@/components/Common/KnowMoreLink/KnowMoreLink';
|
||||
import ToolTip from '../../../../Common/Tooltip/Tooltip';
|
||||
|
||||
type ApolloFederationSupportProps = {
|
||||
toggleApollofederation: () => void;
|
||||
isApolloFederationSupported: boolean;
|
||||
};
|
||||
|
||||
export const ApolloFederationSupport = ({
|
||||
toggleApollofederation,
|
||||
isApolloFederationSupported,
|
||||
}: ApolloFederationSupportProps) => {
|
||||
const { data: configData, isLoading, isError } = useServerConfig();
|
||||
|
||||
if (isError) {
|
||||
return <div>Error in fetching server configuration</div>;
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
const isSupportForApolloFederationEnabled = configData?.experimental_features.includes(
|
||||
'apollo_federation'
|
||||
);
|
||||
return (
|
||||
<div className="mb-lg">
|
||||
<div className="flex items-center mb-formlabel">
|
||||
<h4 className="flex items-center text-gray-600 font-semibold mr-sm">
|
||||
Enable Apollo Federation
|
||||
<ToolTip message="Allows Apollo federated subgraphs to use this table in their schema by adding the `@key` directive" />
|
||||
</h4>
|
||||
<KnowMoreLink
|
||||
href="https://hasura.io/docs/latest/data-federation/apollo-federation/"
|
||||
text="Know More"
|
||||
/>
|
||||
</div>
|
||||
{!isSupportForApolloFederationEnabled ? (
|
||||
<div className="font-thin">
|
||||
Apollo federation is not enabled. To enable apollo federation support,
|
||||
start the Hasura server with environment variable
|
||||
<code>
|
||||
HASURA_GRAPHQL_EXPERIMENTAL_FEATURES: "apollo_federation"
|
||||
</code>
|
||||
</div>
|
||||
) : (
|
||||
<div data-toggle="tooltip">
|
||||
<Toggle
|
||||
icons={false}
|
||||
onChange={() => toggleApollofederation()}
|
||||
checked={isApolloFederationSupported}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
@ -35,23 +35,6 @@ const EnumsSection = ({ isEnum, toggleEnum, loading }) => {
|
||||
title = 'Please wait...';
|
||||
}
|
||||
|
||||
// const getCompatibilityNote = () => {
|
||||
// return (
|
||||
// <div>
|
||||
// <i>
|
||||
// * The table must meet some requirements for you to set it as an enum.{' '}
|
||||
// <a
|
||||
// href={enumCompatibilityDocsUrl}
|
||||
// target="_blank"
|
||||
// rel="noopener noreferrer"
|
||||
// >
|
||||
// See requirements.
|
||||
// </a>
|
||||
// </i>
|
||||
// </div>
|
||||
// );
|
||||
// };
|
||||
|
||||
return (
|
||||
<div className="mb-lg">
|
||||
<div className="flex items-center mb-formlabel">
|
||||
|
@ -21,6 +21,9 @@ import {
|
||||
TOGGLE_ENUM,
|
||||
TOGGLE_ENUM_SUCCESS,
|
||||
TOGGLE_ENUM_FAILURE,
|
||||
TOGGLE_APOLLO_FEDERATION,
|
||||
TOGGLE_APOLLO_FEDERATION_SUCCESS,
|
||||
TOGGLE_APOLLO_FEDERATION_FAILURE,
|
||||
MODIFY_ROOT_FIELD,
|
||||
MODIFY_TABLE_CUSTOM_NAME,
|
||||
SET_CHECK_CONSTRAINTS,
|
||||
@ -624,6 +627,29 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
|
||||
loading: false,
|
||||
},
|
||||
};
|
||||
|
||||
case TOGGLE_APOLLO_FEDERATION:
|
||||
return {
|
||||
...modifyState,
|
||||
tableApolloFederation: {
|
||||
loading: true,
|
||||
},
|
||||
};
|
||||
case TOGGLE_APOLLO_FEDERATION_FAILURE:
|
||||
return {
|
||||
...modifyState,
|
||||
tableApolloFederation: {
|
||||
loading: false,
|
||||
error: action.error,
|
||||
},
|
||||
};
|
||||
case TOGGLE_APOLLO_FEDERATION_SUCCESS:
|
||||
return {
|
||||
...modifyState,
|
||||
tableApolloFederation: {
|
||||
loading: false,
|
||||
},
|
||||
};
|
||||
case MODIFY_TABLE_CUSTOM_NAME:
|
||||
return {
|
||||
...modifyState,
|
||||
|
@ -58,6 +58,7 @@ import {
|
||||
getDropComputedFieldQuery,
|
||||
getSetCustomRootFieldsQuery,
|
||||
getSetTableEnumQuery,
|
||||
getSetTableApolloFederationQuery,
|
||||
} from '../../../../metadata/queryUtils';
|
||||
import { getColumnUpdateMigration } from '../../../../utils/migration/utils';
|
||||
import Migration from '../../../../utils/migration/Migration';
|
||||
@ -96,6 +97,11 @@ const REMOVE_UNIQUE_KEY = 'ModifyTable/REMOVE_UNIQUE_KEY';
|
||||
const TOGGLE_ENUM = 'ModifyTable/TOGGLE_ENUM';
|
||||
const TOGGLE_ENUM_SUCCESS = 'ModifyTable/TOGGLE_ENUM_SUCCESS';
|
||||
const TOGGLE_ENUM_FAILURE = 'ModifyTable/TOGGLE_ENUM_FAILURE';
|
||||
const TOGGLE_APOLLO_FEDERATION = 'ModifyTable/TOGGLE_APOLLO_FEDERATION';
|
||||
const TOGGLE_APOLLO_FEDERATION_SUCCESS =
|
||||
'ModifyTable/TOGGLE_APOLLO_FEDERATION_SUCCESS';
|
||||
const TOGGLE_APOLLO_FEDERATION_FAILURE =
|
||||
'ModifyTable/TOGGLE_APOLLO_FEDERATION_FAILURE';
|
||||
|
||||
const MODIFY_TABLE_CUSTOM_NAME = 'ModifyTable/MODIFY_TABLE_CUSTOM_NAME';
|
||||
const MODIFY_ROOT_FIELD = 'ModifyTable/MODIFY_ROOT_FIELD';
|
||||
@ -117,6 +123,14 @@ const toggleEnumFailure = () => ({
|
||||
type: TOGGLE_ENUM_FAILURE,
|
||||
});
|
||||
|
||||
const toggleApolloFederationFailure = () => ({
|
||||
type: TOGGLE_APOLLO_FEDERATION_FAILURE,
|
||||
});
|
||||
|
||||
const toggleApolloFederationSuccess = () => ({
|
||||
type: TOGGLE_APOLLO_FEDERATION_SUCCESS,
|
||||
});
|
||||
|
||||
const setForeignKeys = fks => ({
|
||||
type: SET_FOREIGN_KEYS,
|
||||
fks,
|
||||
@ -1787,6 +1801,79 @@ export const toggleTableAsEnum = (isEnum, successCallback, failureCallback) => (
|
||||
);
|
||||
};
|
||||
|
||||
export const toggleAsApollofederation = (
|
||||
isApolloFederationSupported,
|
||||
successCallback,
|
||||
failureCallback
|
||||
) => (dispatch, getState) => {
|
||||
const confirmMessage = `This will ${
|
||||
isApolloFederationSupported ? 'disable' : 'add'
|
||||
} the apollo federation support for the table`;
|
||||
const isOk = getConfirmation(confirmMessage);
|
||||
if (!isOk) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch({ type: TOGGLE_APOLLO_FEDERATION });
|
||||
|
||||
const { currentTable, currentSchema, currentDataSource } = getState().tables;
|
||||
const migration = new Migration();
|
||||
migration.add(
|
||||
getSetTableApolloFederationQuery(
|
||||
generateTableDef(currentTable, currentSchema),
|
||||
!isApolloFederationSupported,
|
||||
currentDataSource
|
||||
),
|
||||
getSetTableApolloFederationQuery(
|
||||
generateTableDef(currentTable, currentSchema),
|
||||
isApolloFederationSupported,
|
||||
currentDataSource
|
||||
)
|
||||
);
|
||||
|
||||
const migrationName =
|
||||
'alter_table_' +
|
||||
currentSchema +
|
||||
'_' +
|
||||
currentTable +
|
||||
'_set_apollo_federation_' +
|
||||
!isApolloFederationSupported;
|
||||
|
||||
const action = !isApolloFederationSupported ? 'enabled' : 'disabled';
|
||||
const requestMsg = `Enabling apollo federation support...`;
|
||||
const successMsg = `Apollo federation support is successful ${action}`;
|
||||
const errorMsg = `Enabling apollo federation support failed`;
|
||||
|
||||
const customOnSuccess = () => {
|
||||
if (successCallback) {
|
||||
successCallback();
|
||||
}
|
||||
|
||||
dispatch(toggleApolloFederationSuccess());
|
||||
};
|
||||
|
||||
const customOnError = () => {
|
||||
dispatch(toggleApolloFederationFailure());
|
||||
|
||||
if (failureCallback) {
|
||||
failureCallback();
|
||||
}
|
||||
};
|
||||
|
||||
makeMigrationCall(
|
||||
dispatch,
|
||||
getState,
|
||||
migration.upMigration,
|
||||
migration.downMigration,
|
||||
migrationName,
|
||||
customOnSuccess,
|
||||
customOnError,
|
||||
requestMsg,
|
||||
successMsg,
|
||||
errorMsg
|
||||
);
|
||||
};
|
||||
|
||||
export const saveCheckConstraint = (index, successCb, errorCb) => (
|
||||
dispatch,
|
||||
getState
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
RESET,
|
||||
setUniqueKeys,
|
||||
toggleTableAsEnum,
|
||||
toggleAsApollofederation,
|
||||
} from '../TableModify/ModifyActions';
|
||||
import {
|
||||
setTable,
|
||||
@ -54,6 +55,7 @@ import FeatureDisabled from '../FeatureDisabled';
|
||||
import IndexFields from './IndexFields';
|
||||
import PartitionInfo from './PartitionInfo';
|
||||
import { FaFlask } from 'react-icons/fa';
|
||||
import { ApolloFederationSupport } from '../Common/Components/ApolloFederationSupport';
|
||||
|
||||
class ModifyTable extends React.Component {
|
||||
componentDidMount() {
|
||||
@ -169,6 +171,9 @@ class ModifyTable extends React.Component {
|
||||
);
|
||||
};
|
||||
|
||||
const toggleApollofederation = () =>
|
||||
dispatch(toggleAsApollofederation(table.is_apollo_federation_supported));
|
||||
|
||||
return (
|
||||
<RightContainer>
|
||||
<div>
|
||||
@ -398,6 +403,13 @@ class ModifyTable extends React.Component {
|
||||
{isFeatureSupported('tables.modify.setAsEnum') &&
|
||||
getEnumsSection()}
|
||||
|
||||
<ApolloFederationSupport
|
||||
toggleApollofederation={toggleApollofederation}
|
||||
isApolloFederationSupported={
|
||||
table.is_apollo_federation_supported
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="mb-lg">
|
||||
{isFeatureSupported('tables.modify.untrack') && untrackBtn}
|
||||
{isFeatureSupported('tables.modify.delete') && deleteBtn}
|
||||
|
@ -35,6 +35,7 @@ Array [
|
||||
"computed_fields": Array [],
|
||||
"configuration": Object {},
|
||||
"foreign_key_constraints": Array [],
|
||||
"is_apollo_federation_supported": false,
|
||||
"is_enum": false,
|
||||
"is_table_tracked": true,
|
||||
"opp_foreign_key_constraints": Array [
|
||||
@ -144,6 +145,7 @@ Array [
|
||||
"table_schema": "public",
|
||||
},
|
||||
],
|
||||
"is_apollo_federation_supported": false,
|
||||
"is_enum": false,
|
||||
"is_table_tracked": true,
|
||||
"opp_foreign_key_constraints": Array [],
|
||||
@ -211,6 +213,7 @@ Array [
|
||||
"computed_fields": Array [],
|
||||
"configuration": Object {},
|
||||
"foreign_key_constraints": Array [],
|
||||
"is_apollo_federation_supported": false,
|
||||
"is_enum": false,
|
||||
"is_table_tracked": true,
|
||||
"opp_foreign_key_constraints": Array [],
|
||||
|
@ -355,6 +355,7 @@ export const mergeDataMssql = (
|
||||
view_info: null,
|
||||
remote_relationships: remoteRelationships,
|
||||
is_enum: false,
|
||||
is_apollo_federation_supported: !!metadataTable?.apollo_federation_config,
|
||||
configuration: metadataTable?.configuration as Table['configuration'],
|
||||
computed_fields: [],
|
||||
};
|
||||
@ -427,12 +428,14 @@ export const mergeLoadSchemaDataPostgres = (
|
||||
let refFkConstraints: Table['foreign_key_constraints'] = [];
|
||||
let remoteRelationships: Table['remote_relationships'] = [];
|
||||
let isEnum = false;
|
||||
let isApolloFederationSupported = false;
|
||||
let configuration = {};
|
||||
let computed_fields: Table['computed_fields'] = [];
|
||||
const relationships: Table['relationships'] = [];
|
||||
|
||||
if (metadataTable) {
|
||||
isEnum = metadataTable?.is_enum || false;
|
||||
isApolloFederationSupported = !!metadataTable?.apollo_federation_config;
|
||||
configuration = metadataTable?.configuration || {};
|
||||
|
||||
fkConstraints = trackedFkData.filter(
|
||||
@ -529,6 +532,7 @@ export const mergeLoadSchemaDataPostgres = (
|
||||
view_info: viewInfo as Table['view_info'],
|
||||
remote_relationships: remoteRelationships,
|
||||
is_enum: isEnum,
|
||||
is_apollo_federation_supported: isApolloFederationSupported,
|
||||
configuration: configuration as Table['configuration'],
|
||||
computed_fields,
|
||||
};
|
||||
@ -736,12 +740,14 @@ export const mergeDataCitus = (
|
||||
let refFkConstraints: Table['foreign_key_constraints'] = [];
|
||||
let remoteRelationships: Table['remote_relationships'] = [];
|
||||
let isEnum = false;
|
||||
let isApolloFederationSupported = false;
|
||||
let configuration = {};
|
||||
let computed_fields: Table['computed_fields'] = [];
|
||||
const relationships: Table['relationships'] = [];
|
||||
|
||||
if (metadataTable) {
|
||||
isEnum = metadataTable?.is_enum ?? false;
|
||||
isApolloFederationSupported = !!metadataTable?.apollo_federation_config;
|
||||
configuration = metadataTable?.configuration ?? {};
|
||||
|
||||
fkConstraints = trackedFkData.filter(
|
||||
@ -838,6 +844,7 @@ export const mergeDataCitus = (
|
||||
view_info: viewInfo as Table['view_info'],
|
||||
remote_relationships: remoteRelationships,
|
||||
is_enum: isEnum,
|
||||
is_apollo_federation_supported: isApolloFederationSupported,
|
||||
configuration: configuration as Table['configuration'],
|
||||
computed_fields,
|
||||
citus_table_type,
|
||||
|
@ -30,6 +30,7 @@ export const metadataQueryTypes = [
|
||||
'track_table',
|
||||
'untrack_table',
|
||||
'set_table_is_enum',
|
||||
'set_apollo_federation_config',
|
||||
'track_function',
|
||||
'untrack_function',
|
||||
'create_object_relationship',
|
||||
@ -346,6 +347,19 @@ export const getSetTableEnumQuery = (
|
||||
});
|
||||
};
|
||||
|
||||
export const getSetTableApolloFederationQuery = (
|
||||
tableDef: QualifiedTable,
|
||||
isApolloFederationSupported: boolean,
|
||||
source: string
|
||||
) => {
|
||||
return getMetadataQuery('set_apollo_federation_config', source, {
|
||||
table: tableDef,
|
||||
apollo_federation_config: isApolloFederationSupported
|
||||
? { enable: 'v1' }
|
||||
: null,
|
||||
});
|
||||
};
|
||||
|
||||
export const getTrackTableQuery = ({
|
||||
tableDef,
|
||||
source,
|
||||
|
@ -66,6 +66,7 @@ export interface TableConfig {
|
||||
export interface TableEntry {
|
||||
table: QualifiedTable;
|
||||
is_enum?: boolean;
|
||||
apollo_federation_config?: { enable: 'v1' };
|
||||
configuration?: TableConfig;
|
||||
event_triggers?: EventTrigger[];
|
||||
computed_fields?: ComputedField[];
|
||||
|
@ -101,11 +101,13 @@ The various types of queries are listed in the following table:
|
||||
| [pg_delete_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-delete-event-trigger) | [pg_delete_event_trigger_args](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-delete-event-trigger-syntax) | 1 | Delete an existing event trigger on a Postgres table |
|
||||
| [pg_redeliver_event](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-redeliver-event) | [pg_redeliver_event_args](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-redeliver-event-syntax) | 1 | Redeliver an existing event on a Postgres table |
|
||||
| [pg_invoke_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-invoke-event-trigger) | [pg_invoke_event_trigger_args](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-invoke-event-trigger-syntax) | 1 | Invoke a trigger with custom payload on a Postgres table |
|
||||
| [pg_set_apollo_federation_config](/api-reference/metadata-api/table-view.mdx#metadata-pg-set-apollo-federation-config) | [pg_set_apollo_federation_config_args](/api-reference/metadata-api/table-view.mdx#metadata-pg-set-apollo-federation-config-syntax) | 1 | Set Apollo Federaion configuration of an already tracked postgres table|
|
||||
| [bigquery_track_table](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-track-table) | [bigquery_track_table_args](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-track-table-syntax) | 1 | Add a BigQuery table/view with configuration |
|
||||
| [bigquery_untrack_table](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-untrack-table) | [bigquery_untrack_table_args](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-untrack-table-syntax) | 1 | Remove a BigQuery table/view |
|
||||
| [bigquery_set_table_customization](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-set-table-customization) | [bigquery_set_table_customization_args](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-set-table-customization-syntax) | 1 | Set table customization of an already tracked BigQuery table |
|
||||
| [bigquery_add_computed_field](/api-reference/metadata-api/computed-field.mdx#metadata-bigquery-add-computed-field) | [bigquery_add_computed_field_args](/api-reference/metadata-api/computed-field.mdx#metadata-bigquery-add-computed-field-syntax) | 1 | Add a computed field to a BigQuery table |
|
||||
| [bigquery_drop_computed_field](/api-reference/metadata-api/computed-field.mdx#metadata-bigquery-drop-computed-field) | [bigquery_drop_computed_field_args](/api-reference/metadata-api/computed-field.mdx#metadata-bigquery-drop-computed-field-syntax) | 1 | Drop a BigQuery computed field |
|
||||
| [bigquery_set_apollo_federation_config](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-set-apollo-federation-config) | [bigquery_set_apollo_federation_config_args](/api-reference/metadata-api/table-view.mdx#metadata-bigquery-set-apollo-federation-config-syntax) | 1 | Set Apollo Federaion configuration of an already tracked bigquery table|
|
||||
| [mssql_add_source](/api-reference/metadata-api/source.mdx#mssql-add-source) | [mssql_add_source_args](/api-reference/metadata-api/source.mdx#mssql-add-source-syntax) | 1 | Add an MS SQL Server database |
|
||||
| [mssql_drop_source](/api-reference/metadata-api/source.mdx#mssql-drop-source) | [mssql_drop_source_args](/api-reference/metadata-api/source.mdx#mssql-drop-source-syntax) | 1 | Remove an MS SQL Server database |
|
||||
| [mssql_track_table](/api-reference/metadata-api/table-view.mdx#mssql-track-table) | [mssql_track_table_args](/api-reference/metadata-api/table-view.mdx#mssql-track-table-syntax) | 1 | Add an MS SQL Server table/view with configuration |
|
||||
@ -126,6 +128,7 @@ The various types of queries are listed in the following table:
|
||||
| [mssql_create_delete_permission](/api-reference/metadata-api/permission.mdx#mssql-create-delete-permission) | [mssql_create_delete_permission_args](/api-reference/metadata-api/permission.mdx#mssql-create-delete-permission-syntax) | 1 | Specify delete permission for an MS SQL Server table/view |
|
||||
| [mssql_drop_delete_permission](/api-reference/metadata-api/permission.mdx#mssql-drop-delete-permission) | [mssql_drop_delete_permission_args](/api-reference/metadata-api/permission.mdx#mssql-drop-delete-permission-syntax) | 1 | Remove existing delete permission for an MS SQL Server table/view |
|
||||
| [mssql_set_permission_comment](/api-reference/metadata-api/permission.mdx#mssql-set-permission-comment) | [mssql_set_permission_comment_args](/api-reference/metadata-api/permission.mdx#mssql-set-permission-comment-syntax) | 1 | Set comment on an existing permission for an MS SQL Server table/view |
|
||||
| [mssql_set_apollo_federation_config](/api-reference/metadata-api/table-view.mdx#metadata-mssql-set-apollo-federation-config) | [mssql_set_apollo_federation_config_args](/api-reference/metadata-api/table-view.mdx#metadata-mssql-set-apollo-federation-config-syntax) | 1 | Set Apollo Federaion configuration of an already tracked mssql table |
|
||||
| [create_cron_trigger](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-create-cron-trigger) | [create_cron_trigger_args](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-create-cron-trigger-syntax) | 1 | Create a cron trigger |
|
||||
| [delete_cron_trigger](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-delete-cron-trigger) | [delete_cron_trigger_args](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-delete-cron-trigger-syntax) | 1 | Delete an existing cron trigger |
|
||||
| [get_cron_triggers](/api-reference/metadata-api/scheduled-triggers.mdx#metadata-get-cron-triggers) | [Empty Object](/api-reference/syntax-defs.mdx#empty-object) | 1 | Returns all the cron triggers |
|
||||
|
@ -234,6 +234,44 @@ X-Hasura-Role: admin
|
||||
| configuration | false | [TableConfig](/api-reference/syntax-defs.mdx#table-config) | Configuration for the table/view |
|
||||
| source | false | [SourceName](/api-reference/syntax-defs.mdx#sourcename) | Name of the source database of the table (default: `default`) |
|
||||
|
||||
## pg_set_apollo_federation_config {#metadata-pg-set-apollo-federation-config}
|
||||
|
||||
`pg_set_apollo_federation_config` allows you to set apollo federation configuration for an already tracked postgres
|
||||
table. Enabling Apollo Federation will allow you to use the table type generated by Hasura in other subgraphs.
|
||||
|
||||
Set the Apollo Federation configuration for a postgres table called `author`:
|
||||
|
||||
```http
|
||||
POST /v1/metadata HTTP/1.1
|
||||
Content-Type: application/json
|
||||
X-Hasura-Role: admin
|
||||
|
||||
{
|
||||
"type": "pg_set_apollo_federation_config",
|
||||
"args": {
|
||||
"table": "author_details",
|
||||
"source": "default",
|
||||
"apollo_federation_config": {
|
||||
"enable": "v1"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Args syntax {#metadata-pg-set-apollo-federation-config-syntax}
|
||||
|
||||
| Key | Required | Schema | Description |
|
||||
|--------------------------|----------|---------------------------------------------------------------------------------|---------------------------------------------------------------|
|
||||
| table | true | [TableName](/api-reference/syntax-defs.mdx#tablename) | Name of the table |
|
||||
| source | false | [SourceName](/api-reference/syntax-defs.mdx#sourcename) | Name of the source database of the table (default: `default`) |
|
||||
| apollo_federation_config | false | [ApolloFederationConfig](/api-reference/syntax-defs.mdx#apollofederationconfig) | Configuration for the table/view |
|
||||
|
||||
:::info Note
|
||||
|
||||
Setting `apollo_federation_config` to `null` will disable Apollo Federation support on the table.
|
||||
|
||||
:::
|
||||
|
||||
## mssql_track_table {#mssql-track-table}
|
||||
|
||||
`mssql_track_table` is used to add a table/view to the GraphQL schema with configuration. You can customise the root
|
||||
@ -385,6 +423,44 @@ X-Hasura-Role: admin
|
||||
| configuration | false | [TableConfig](/api-reference/syntax-defs.mdx#table-config) | Configuration for the table/view |
|
||||
| source | false | [SourceName](/api-reference/syntax-defs.mdx#sourcename) | Name of the source database of the table (default: `default`) |
|
||||
|
||||
## mssql_set_apollo_federation_config {#metadata-mssql-set-apollo-federation-config}
|
||||
|
||||
`mssql_set_apollo_federation_config` allows you to set apollo federation configuration for an already tracked mssql
|
||||
table. Enabling Apollo Federation will allow you to use the table type generated by Hasura in other subgraphs.
|
||||
|
||||
Set the Apollo Federation configuration for a mssql table called `author`:
|
||||
|
||||
```http
|
||||
POST /v1/metadata HTTP/1.1
|
||||
Content-Type: application/json
|
||||
X-Hasura-Role: admin
|
||||
|
||||
{
|
||||
"type": "mssql_set_apollo_federation_config",
|
||||
"args": {
|
||||
"table": "author_details",
|
||||
"source": "default",
|
||||
"apollo_federation_config": {
|
||||
"enable": "v1"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Args syntax {#metadata-mssql-set-apollo-federation-config-syntax}
|
||||
|
||||
| Key | Required | Schema | Description |
|
||||
|--------------------------|----------|---------------------------------------------------------------------------------|---------------------------------------------------------------|
|
||||
| table | true | [TableName](/api-reference/syntax-defs.mdx#tablename) | Name of the table |
|
||||
| source | false | [SourceName](/api-reference/syntax-defs.mdx#sourcename) | Name of the source database of the table (default: `default`) |
|
||||
| apollo_federation_config | false | [ApolloFederationConfig](/api-reference/syntax-defs.mdx#apollofederationconfig) | Configuration for the table/view |
|
||||
|
||||
:::info Note
|
||||
|
||||
Setting `apollo_federation_config` to `null` will disable Apollo Federation support on the table.
|
||||
|
||||
:::
|
||||
|
||||
## bigquery_track_table {#metadata-bigquery-track-table}
|
||||
|
||||
`bigquery_track_table` is used to add a table/view to the GraphQL schema with configuration. You can customise the root
|
||||
@ -576,3 +652,41 @@ X-Hasura-Role: admin
|
||||
| table | true | {"dataset":\_, "name":\_} | Name of the table |
|
||||
| configuration | false | [TableConfig](/api-reference/syntax-defs.mdx#table-config) | Configuration for the table/view |
|
||||
| source | false | [SourceName](/api-reference/syntax-defs.mdx#sourcename) | Name of the source database of the table (default: `default`) |
|
||||
|
||||
## bigquery_set_apollo_federation_config {#metadata-bigquery-set-apollo-federation-config}
|
||||
|
||||
`bigquery_set_apollo_federation_config` allows you to set apollo federation configuration for an already tracked
|
||||
bigquery table. Enabling Apollo Federation will allow you to use the table type generated by Hasura in other subgraphs.
|
||||
|
||||
Set the Apollo Federation configuration for a bigquery table called `author`:
|
||||
|
||||
```http
|
||||
POST /v1/metadata HTTP/1.1
|
||||
Content-Type: application/json
|
||||
X-Hasura-Role: admin
|
||||
|
||||
{
|
||||
"type": "bigquery_set_apollo_federation_config",
|
||||
"args": {
|
||||
"table": "author_details",
|
||||
"source": "default",
|
||||
"apollo_federation_config": {
|
||||
"enable": "v1"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Args syntax {#metadata-bigquery-set-apollo-federation-config-syntax}
|
||||
|
||||
| Key | Required | Schema | Description |
|
||||
|--------------------------|----------|---------------------------------------------------------------------------------|---------------------------------------------------------------|
|
||||
| table | true | [TableName](/api-reference/syntax-defs.mdx#tablename) | Name of the table |
|
||||
| source | false | [SourceName](/api-reference/syntax-defs.mdx#sourcename) | Name of the source database of the table (default: `default`) |
|
||||
| apollo_federation_config | false | [ApolloFederationConfig](/api-reference/syntax-defs.mdx#apollofederationconfig) | Configuration for the table/view |
|
||||
|
||||
:::info Note
|
||||
|
||||
Setting `apollo_federation_config` to `null` will disable Apollo Federation support on the table.
|
||||
|
||||
:::
|
||||
|
@ -12,6 +12,7 @@ keywords:
|
||||
---
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
import Thumbnail from '@site/src/components/Thumbnail';
|
||||
|
||||
# Apollo Federation support
|
||||
|
||||
@ -49,6 +50,11 @@ type user @key(fields: "id") {
|
||||
}
|
||||
```
|
||||
|
||||
The Apollo Federation support in Hasura only allows extending other subgraphs with Hasura types. The other way i.e.
|
||||
extending Hasura types with other subgraphs is not possible currently. We recommend using
|
||||
[remote relationships](/remote-schemas/remote-relationships/index.mdx) for extending types from other subgraphs in
|
||||
Hasura.
|
||||
|
||||
:::note Note
|
||||
|
||||
Other types such as action types, remote schema types, etc. cannot be extended to other subgraphs.
|
||||
@ -58,7 +64,13 @@ Other types such as action types, remote schema types, etc. cannot be extended t
|
||||
<Tabs className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
_Hasura Console support will be added soon._
|
||||
Head to the `Data -> [table-name] -> Modify` tab in the console and toggle the switch in the `Enable Apollo Federation`
|
||||
section:
|
||||
|
||||
<Thumbnail
|
||||
src="/img/graphql/core/data-federation/apollo-federation-enable.png"
|
||||
alt="Set table as enum"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="cli" label="CLI">
|
||||
@ -85,7 +97,7 @@ hasura metadata apply
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
To extend the types using the [Hasura Metadata API](/api-reference/metadata-api/table-view.mdx), you can to enable
|
||||
it with the particular `*_track_table` call:
|
||||
it with the particular `*_set_apollo_federation_config` call:
|
||||
|
||||
```http {16-18}
|
||||
POST /v1/metadata HTTP/1.1
|
||||
@ -93,10 +105,10 @@ Content-Type: application/json
|
||||
X-Hasura-Role: admin
|
||||
|
||||
{
|
||||
"type": "pg_track_table",
|
||||
"type": "pg_set_apollo_federation_config",
|
||||
"args": {
|
||||
"source": "<source_name>",
|
||||
"table": "<table_name>",
|
||||
"schema": "<schema_name>",
|
||||
"apollo_federation_config": {
|
||||
"enable": "v1"
|
||||
}
|
||||
@ -105,4 +117,4 @@ X-Hasura-Role: admin
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
</Tabs>
|
||||
|
BIN
docs/static/img/graphql/core/data-federation/apollo-federation-enable.png
vendored
Normal file
BIN
docs/static/img/graphql/core/data-federation/apollo-federation-enable.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
@ -17,6 +17,8 @@ module Hasura.RQL.DDL.Schema.Table
|
||||
runSetTableCustomization,
|
||||
buildTableCache,
|
||||
checkConflictingNode,
|
||||
SetApolloFederationConfig (..),
|
||||
runSetApolloFederationConfig,
|
||||
)
|
||||
where
|
||||
|
||||
@ -643,3 +645,35 @@ buildTableCache = Inc.cache proc (source, sourceConfig, dbTablesMeta, tableBuild
|
||||
where
|
||||
autogeneratedDescription =
|
||||
PGDescription $ "columns and relationships of " <>> tableName
|
||||
|
||||
data SetApolloFederationConfig b = SetApolloFederationConfig
|
||||
{ _safcSource :: SourceName,
|
||||
_safcTable :: TableName b,
|
||||
-- | Apollo Federation config for the table, setting `Nothing` would disable
|
||||
-- Apollo Federation support on the table.
|
||||
_safcApolloFederationConfig :: Maybe ApolloFederationConfig
|
||||
}
|
||||
|
||||
instance (Backend b) => FromJSON (SetApolloFederationConfig b) where
|
||||
parseJSON = withObject "SetApolloFederationConfig" $ \o ->
|
||||
SetApolloFederationConfig
|
||||
<$> o .:? "source" .!= defaultSource
|
||||
<*> o .: "table"
|
||||
<*> o .:? "apollo_federation_config"
|
||||
|
||||
runSetApolloFederationConfig ::
|
||||
forall b m.
|
||||
(QErrM m, CacheRWM m, MetadataM m, Backend b, BackendMetadata b) =>
|
||||
SetApolloFederationConfig b ->
|
||||
m EncJSON
|
||||
runSetApolloFederationConfig (SetApolloFederationConfig source table apolloFedConfig) = do
|
||||
void $ askTableInfo @b source table
|
||||
buildSchemaCacheFor
|
||||
(MOSourceObjId source $ AB.mkAnyBackend $ SMOTable @b table)
|
||||
-- NOTE (paritosh): This API behaves like a PUT API now. In future, when
|
||||
-- the `ApolloFederationConfig` is complex, we should probably reconsider
|
||||
-- this approach of replacing the configuration everytime the API is called
|
||||
-- and maybe throw some error if the configuration is already there.
|
||||
$ MetadataModifier $
|
||||
tableMetadataSetter @b source table . tmApolloFederationConfig .~ apolloFedConfig
|
||||
return successMsg
|
||||
|
@ -104,6 +104,7 @@ sourceCommands =
|
||||
[ commandParserWithBackendKind "add_source" $ RMAddSource . mkAnyBackend @b,
|
||||
commandParser "drop_source" $ RMDropSource,
|
||||
commandParser "set_table_customization" $ RMSetTableCustomization . mkAnyBackend @b,
|
||||
commandParser "set_apollo_federation_config" $ RMSetApolloFederationConfig . mkAnyBackend @b,
|
||||
commandParserWithBackendKind "update_source" $ RMUpdateSource . mkAnyBackend @b
|
||||
]
|
||||
tableCommands =
|
||||
|
@ -83,6 +83,7 @@ data RQLMetadataV1
|
||||
RMTrackTable !(AnyBackend TrackTableV2)
|
||||
| RMUntrackTable !(AnyBackend UntrackTable)
|
||||
| RMSetTableCustomization !(AnyBackend SetTableCustomization)
|
||||
| RMSetApolloFederationConfig (AnyBackend SetApolloFederationConfig)
|
||||
| -- Tables (PG-specific)
|
||||
RMPgSetTableIsEnum !SetTableIsEnum
|
||||
| -- Tables permissions
|
||||
@ -436,6 +437,7 @@ runMetadataQueryV1M env currentResourceVersion = \case
|
||||
RMUntrackTable q -> dispatchMetadataAndEventTrigger runUntrackTableQ q
|
||||
RMSetFunctionCustomization q -> dispatchMetadata runSetFunctionCustomization q
|
||||
RMSetTableCustomization q -> dispatchMetadata runSetTableCustomization q
|
||||
RMSetApolloFederationConfig q -> dispatchMetadata runSetApolloFederationConfig q
|
||||
RMPgSetTableIsEnum q -> runSetExistingTableIsEnumQ q
|
||||
RMCreateInsertPermission q -> dispatchMetadata runCreatePerm q
|
||||
RMCreateSelectPermission q -> dispatchMetadata runCreatePerm q
|
||||
|
@ -39,6 +39,7 @@ data RQLMetadataV1
|
||||
RMTrackTable !(AnyBackend TrackTableV2)
|
||||
| RMUntrackTable !(AnyBackend UntrackTable)
|
||||
| RMSetTableCustomization !(AnyBackend SetTableCustomization)
|
||||
| RMSetApolloFederationConfig (AnyBackend SetApolloFederationConfig)
|
||||
| -- Tables (PG-specific)
|
||||
RMPgSetTableIsEnum !SetTableIsEnum
|
||||
| -- Tables permissions
|
||||
|
@ -1,68 +1,153 @@
|
||||
description: Introspection to check query fields and their types
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
query:
|
||||
query: |
|
||||
query {
|
||||
__schema {
|
||||
queryType {
|
||||
fields {
|
||||
name
|
||||
type {
|
||||
- description: Introspection to check query fields and their types
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
query:
|
||||
query: |
|
||||
query {
|
||||
__schema {
|
||||
queryType {
|
||||
fields {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response:
|
||||
data:
|
||||
__schema:
|
||||
queryType:
|
||||
fields:
|
||||
- name: _entities
|
||||
type:
|
||||
name: _Entity
|
||||
kind: UNION
|
||||
ofType:
|
||||
- name: _service
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name: _Service
|
||||
kind: OBJECT
|
||||
response:
|
||||
data:
|
||||
__schema:
|
||||
queryType:
|
||||
fields:
|
||||
- name: _entities
|
||||
type:
|
||||
name: _Entity
|
||||
kind: UNION
|
||||
ofType:
|
||||
- name: user
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
- name: _service
|
||||
type:
|
||||
name:
|
||||
kind: LIST
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name: _Service
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
- name: user
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
- name: user_aggregate
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name: user_aggregate
|
||||
kind: LIST
|
||||
ofType:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
- name: user_aggregate
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name: user_aggregate
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
- name: user_by_pk
|
||||
type:
|
||||
name: user
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
- name: user_by_pk
|
||||
type:
|
||||
name: user
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
|
||||
- description: disable apollo federation for user
|
||||
url: /v1/metadata
|
||||
status: 200
|
||||
query:
|
||||
type: pg_set_apollo_federation_config
|
||||
args:
|
||||
table: user
|
||||
apollo_federation_config: NULL
|
||||
response:
|
||||
message: success
|
||||
|
||||
- description: Introspection to check query fields and their types
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
query:
|
||||
query: |
|
||||
query {
|
||||
__schema {
|
||||
queryType {
|
||||
fields {
|
||||
name
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
response:
|
||||
data:
|
||||
__schema:
|
||||
queryType:
|
||||
fields:
|
||||
- name: _service
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name: _Service
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
- name: user
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name:
|
||||
kind: LIST
|
||||
ofType:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
- name: user_aggregate
|
||||
type:
|
||||
name:
|
||||
kind: NON_NULL
|
||||
ofType:
|
||||
name: user_aggregate
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
- name: user_by_pk
|
||||
type:
|
||||
name: user
|
||||
kind: OBJECT
|
||||
ofType:
|
||||
|
||||
- description: enable apollo federation for user
|
||||
url: /v1/metadata
|
||||
status: 200
|
||||
query:
|
||||
type: pg_set_apollo_federation_config
|
||||
args:
|
||||
table: user
|
||||
apollo_federation_config:
|
||||
enable: v1
|
||||
response:
|
||||
message: success
|
Loading…
Reference in New Issue
Block a user