Add kind and version to examples (#451)

<!-- Thank you for submitting this PR! :) -->

## Description

The docs.hasura.io site pulls through these examples for documentation.
We'd like to make them more copy/paste-friendly, so we add these fields
even though they're technically discriminators from parent types.

## Changelog

- Add a changelog entry (in the "Changelog entry" section below) if the
changes in this PR have any user-facing impact. See [changelog
guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide).
- If no changelog is required ignore/remove this section and add a
`no-changelog-required` label to the PR.

### Product
_(Select all products this will be available in)_
- [ ] community-edition
- [ ] 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
- [ ] 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
-->

_Replace with changelog entry_

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

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

V3_GIT_ORIGIN_REV_ID: 9c121367fba187b11801f023208733b1c9ce0337
This commit is contained in:
Tom Harding 2024-04-24 14:34:22 +02:00 committed by hasura-bot
parent d1a8514a2b
commit 03856be0e0
8 changed files with 715 additions and 641 deletions

View File

@ -22,6 +22,40 @@
"$id": "https://hasura.io/jsonschemas/metadata/DataConnectorLink",
"title": "DataConnectorLink",
"description": "Definition of a data connector, used to bring in sources of data and connect them to OpenDD models and commands.",
"examples": [
{
"kind": "DataConnectorLink",
"version": "v1",
"definition": {
"name": "data_connector",
"url": {
"singleUrl": {
"value": "http://data_connector:8100"
}
},
"headers": {},
"schema": {
"version": "v0.1",
"schema": {
"scalar_types": {},
"object_types": {},
"collections": [],
"functions": [],
"procedures": []
},
"capabilities": {
"version": "0.1.0",
"capabilities": {
"query": {
"variables": {}
},
"mutation": {}
}
}
}
}
}
],
"oneOf": [
{
"type": "object",
@ -55,6 +89,52 @@
"$id": "https://hasura.io/jsonschemas/metadata/ObjectType",
"title": "ObjectType",
"description": "Definition of a user-defined Open DD object type.",
"examples": [
{
"kind": "ObjectType",
"version": "v1",
"definition": {
"name": "Author",
"fields": [
{
"name": "author_id",
"type": "Int!",
"description": "The id of the author"
},
{
"name": "first_name",
"type": "String",
"description": "The first name of the author"
},
{
"name": "last_name",
"type": "String",
"description": "The last name of the author"
}
],
"description": "An author of a book",
"globalIdFields": [
"author_id"
],
"graphql": {
"typeName": "Author"
},
"dataConnectorTypeMapping": [
{
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"fieldMapping": {
"author_id": {
"column": {
"name": "id"
}
}
}
}
]
}
}
],
"oneOf": [
{
"type": "object",
@ -88,6 +168,17 @@
"$id": "https://hasura.io/jsonschemas/metadata/ScalarType",
"title": "ScalarType",
"description": "Definition of a user-defined scalar type that that has opaque semantics.",
"examples": [
{
"kind": "ScalarType",
"version": "v1",
"name": "CustomString",
"graphql": {
"typeName": "CustomString"
},
"description": "A custom string type"
}
],
"oneOf": [
{
"type": "object",
@ -121,6 +212,41 @@
"$id": "https://hasura.io/jsonschemas/metadata/ObjectBooleanExpressionType",
"title": "ObjectBooleanExpressionType",
"description": "Definition of a type representing a boolean expression on an Open DD object type.",
"examples": [
{
"kind": "ObjectBooleanExpressionType",
"version": "v1",
"definition": {
"name": "AuthorBoolExp",
"objectType": "Author",
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"comparableFields": [
{
"fieldName": "article_id",
"operators": {
"enableAll": true
}
},
{
"fieldName": "title",
"operators": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"operators": {
"enableAll": true
}
}
],
"graphql": {
"typeName": "Author_bool_exp"
}
}
}
],
"oneOf": [
{
"type": "object",
@ -187,6 +313,64 @@
"$id": "https://hasura.io/jsonschemas/metadata/Model",
"title": "Model",
"description": "The definition of a data model. A data model is a collection of objects of a particular type. Models can support one or more CRUD operations.",
"examples": [
{
"kind": "Model",
"version": "v1",
"definition": {
"name": "Articles",
"objectType": "article",
"globalIdSource": true,
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"collection": "articles",
"argumentMapping": {}
},
"filterExpressionType": "Article_bool_exp",
"orderableFields": [
{
"fieldName": "article_id",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "title",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"orderByDirections": {
"enableAll": true
}
}
],
"graphql": {
"selectUniques": [
{
"queryRootField": "ArticleByID",
"uniqueIdentifier": [
"article_id"
],
"description": "Description for the select unique ArticleByID"
}
],
"selectMany": {
"queryRootField": "ArticleMany",
"description": "Description for the select many ArticleMany"
},
"orderByExpressionType": "Article_Order_By",
"apolloFederation": {
"entitySource": true
}
},
"description": "Description for the model Articles"
}
}
],
"oneOf": [
{
"type": "object",
@ -220,6 +404,29 @@
"$id": "https://hasura.io/jsonschemas/metadata/Command",
"title": "Command",
"description": "The definition of a command. A command is a user-defined operation which can take arguments and returns an output. The semantics of a command are opaque to the Open DD specification.",
"examples": [
{
"kind": "Command",
"version": "v1",
"definition": {
"name": "get_latest_article",
"outputType": "commandArticle",
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"dataConnectorCommand": {
"function": "latest_article"
},
"argumentMapping": {}
},
"graphql": {
"rootFieldName": "getLatestArticle",
"rootFieldKind": "Query"
},
"description": "Get the latest article"
}
}
],
"oneOf": [
{
"type": "object",
@ -253,6 +460,42 @@
"$id": "https://hasura.io/jsonschemas/metadata/Relationship",
"title": "Relationship",
"description": "Definition of a relationship on an OpenDD type which allows it to be extended with related models or commands.",
"examples": [
{
"kind": "Relationship",
"version": "v1",
"definition": {
"name": "Articles",
"source": "author",
"target": {
"model": {
"name": "Articles",
"subgraph": null,
"relationshipType": "Array"
}
},
"mapping": [
{
"source": {
"fieldPath": [
{
"fieldName": "author_id"
}
]
},
"target": {
"modelField": [
{
"fieldName": "author_id"
}
]
}
}
],
"description": "Articles written by an author"
}
}
],
"oneOf": [
{
"type": "object",
@ -286,6 +529,36 @@
"$id": "https://hasura.io/jsonschemas/metadata/TypePermissions",
"title": "TypePermissions",
"description": "Definition of permissions for an OpenDD type.",
"examples": [
{
"kind": "TypePermissions",
"version": "v1",
"definition": {
"typeName": "article",
"permissions": [
{
"role": "admin",
"output": {
"allowedFields": [
"article_id",
"author_id",
"title"
]
}
},
{
"role": "user",
"output": {
"allowedFields": [
"article_id",
"author_id"
]
}
}
]
}
}
],
"oneOf": [
{
"type": "object",
@ -319,6 +592,37 @@
"$id": "https://hasura.io/jsonschemas/metadata/ModelPermissions",
"title": "ModelPermissions",
"description": "Definition of permissions for an OpenDD model.",
"examples": [
{
"kind": "ModelPermissions",
"version": "v1",
"definition": {
"modelName": "Articles",
"permissions": [
{
"role": "admin",
"select": {
"filter": null
}
},
{
"role": "user",
"select": {
"filter": {
"fieldComparison": {
"field": "author_id",
"operator": "_eq",
"value": {
"sessionVariable": "x-hasura-user-id"
}
}
}
}
}
]
}
}
],
"oneOf": [
{
"type": "object",
@ -352,6 +656,25 @@
"$id": "https://hasura.io/jsonschemas/metadata/CommandPermissions",
"title": "CommandPermissions",
"description": "Definition of permissions for an OpenDD command.",
"examples": [
{
"kind": "CommandPermissions",
"version": "v1",
"definition": {
"commandName": "get_article_by_id",
"permissions": [
{
"role": "admin",
"allowExecution": true
},
{
"role": "user",
"allowExecution": true
}
]
}
}
],
"oneOf": [
{
"type": "object",
@ -387,36 +710,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/DataConnectorLinkV1",
"title": "DataConnectorLinkV1",
"description": "Definition of a data connector - version 1.",
"examples": [
{
"name": "data_connector",
"url": {
"singleUrl": {
"value": "http://data_connector:8100"
}
},
"headers": {},
"schema": {
"version": "v0.1",
"schema": {
"scalar_types": {},
"object_types": {},
"collections": [],
"functions": [],
"procedures": []
},
"capabilities": {
"version": "0.1.0",
"capabilities": {
"query": {
"variables": {}
},
"mutation": {}
}
}
}
}
],
"type": "object",
"required": [
"name",
@ -589,48 +882,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/ObjectTypeV1",
"title": "ObjectTypeV1",
"description": "Definition of a user-defined Open DD object type.",
"examples": [
{
"name": "Author",
"fields": [
{
"name": "author_id",
"type": "Int!",
"description": "The id of the author"
},
{
"name": "first_name",
"type": "String",
"description": "The first name of the author"
},
{
"name": "last_name",
"type": "String",
"description": "The last name of the author"
}
],
"description": "An author of a book",
"globalIdFields": [
"author_id"
],
"graphql": {
"typeName": "Author"
},
"dataConnectorTypeMapping": [
{
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"fieldMapping": {
"author_id": {
"column": {
"name": "id"
}
}
}
}
]
}
],
"type": "object",
"required": [
"fields",
@ -930,15 +1181,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/ScalarTypeV1",
"title": "ScalarTypeV1",
"description": "Definition of a user-defined scalar type that that has opaque semantics.",
"examples": [
{
"name": "CustomString",
"graphql": {
"typeName": "CustomString"
},
"description": "A custom string type"
}
],
"type": "object",
"required": [
"name"
@ -997,37 +1239,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/ObjectBooleanExpressionTypeV1",
"title": "ObjectBooleanExpressionTypeV1",
"description": "Definition of a type representing a boolean expression on an Open DD object type.",
"examples": [
{
"name": "AuthorBoolExp",
"objectType": "Author",
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"comparableFields": [
{
"fieldName": "article_id",
"operators": {
"enableAll": true
}
},
{
"fieldName": "title",
"operators": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"operators": {
"enableAll": true
}
}
],
"graphql": {
"typeName": "Author_bool_exp"
}
}
],
"type": "object",
"required": [
"comparableFields",
@ -1263,60 +1474,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/ModelV1",
"title": "ModelV1",
"description": "The definition of a data model. A data model is a collection of objects of a particular type. Models can support one or more CRUD operations.",
"examples": [
{
"name": "Articles",
"objectType": "article",
"globalIdSource": true,
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"collection": "articles",
"argumentMapping": {}
},
"filterExpressionType": "Article_bool_exp",
"orderableFields": [
{
"fieldName": "article_id",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "title",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"orderByDirections": {
"enableAll": true
}
}
],
"graphql": {
"selectUniques": [
{
"queryRootField": "ArticleByID",
"uniqueIdentifier": [
"article_id"
],
"description": "Description for the select unique ArticleByID"
}
],
"selectMany": {
"queryRootField": "ArticleMany",
"description": "Description for the select many ArticleMany"
},
"orderByExpressionType": "Article_Order_By",
"apolloFederation": {
"entitySource": true
}
},
"description": "Description for the model Articles"
}
],
"type": "object",
"required": [
"name",
@ -1740,25 +1897,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/CommandV1",
"title": "CommandV1",
"description": "Definition of an OpenDD Command, which is a custom operation that can take arguments and returns an output. The semantics of a command are opaque to OpenDD.",
"examples": [
{
"name": "get_latest_article",
"outputType": "commandArticle",
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"dataConnectorCommand": {
"function": "latest_article"
},
"argumentMapping": {}
},
"graphql": {
"rootFieldName": "getLatestArticle",
"rootFieldKind": "Query"
},
"description": "Get the latest article"
}
],
"type": "object",
"required": [
"name",
@ -1974,38 +2112,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/RelationshipV1",
"title": "RelationshipV1",
"description": "Definition of a relationship on an OpenDD type which allows it to be extended with related models or commands.",
"examples": [
{
"name": "Articles",
"source": "author",
"target": {
"model": {
"name": "Articles",
"subgraph": null,
"relationshipType": "Array"
}
},
"mapping": [
{
"source": {
"fieldPath": [
{
"fieldName": "author_id"
}
]
},
"target": {
"modelField": [
{
"fieldName": "author_id"
}
]
}
}
],
"description": "Articles written by an author"
}
],
"type": "object",
"required": [
"mapping",
@ -2383,32 +2489,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/TypePermissionsV1",
"title": "TypePermissionsV1",
"description": "Definition of permissions for an OpenDD type.",
"examples": [
{
"typeName": "article",
"permissions": [
{
"role": "admin",
"output": {
"allowedFields": [
"article_id",
"author_id",
"title"
]
}
},
{
"role": "user",
"output": {
"allowedFields": [
"article_id",
"author_id"
]
}
}
]
}
],
"type": "object",
"required": [
"permissions",
@ -2602,33 +2682,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/ModelPermissionsV1",
"title": "ModelPermissionsV1",
"description": "Definition of permissions for an OpenDD model.",
"examples": [
{
"modelName": "Articles",
"permissions": [
{
"role": "admin",
"select": {
"filter": null
}
},
{
"role": "user",
"select": {
"filter": {
"fieldComparison": {
"field": "author_id",
"operator": "_eq",
"value": {
"sessionVariable": "x-hasura-user-id"
}
}
}
}
}
]
}
],
"type": "object",
"required": [
"modelName",
@ -2972,21 +3025,6 @@
"$id": "https://hasura.io/jsonschemas/metadata/CommandPermissionsV1",
"title": "CommandPermissionsV1",
"description": "Definition of permissions for an OpenDD command.",
"examples": [
{
"commandName": "get_article_by_id",
"permissions": [
{
"role": "admin",
"allowExecution": true
},
{
"role": "user",
"allowExecution": true
}
]
}
],
"type": "object",
"required": [
"commandName",

View File

@ -57,12 +57,39 @@ pub enum DataConnectorCommand {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "Command"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "Command", example = "Command::example")
)]
pub enum Command {
V1(CommandV1),
}
impl Command {
fn example() -> serde_json::Value {
serde_json::json!({
"kind": "Command",
"version": "v1",
"definition": {
"name": "get_latest_article",
"outputType": "commandArticle",
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"dataConnectorCommand": {
"function": "latest_article"
},
"argumentMapping": {}
},
"graphql": {
"rootFieldName": "getLatestArticle",
"rootFieldKind": "Query"
},
"description": "Get the latest article",
}
})
}
pub fn upgrade(self) -> CommandV1 {
match self {
Command::V1(v1) => v1,
@ -72,7 +99,7 @@ impl Command {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "CommandV1", example = "CommandV1::example"))]
#[opendd(json_schema(title = "CommandV1"))]
/// Definition of an OpenDD Command, which is a custom operation that can take arguments and
/// returns an output. The semantics of a command are opaque to OpenDD.
pub struct CommandV1 {
@ -92,28 +119,6 @@ pub struct CommandV1 {
pub description: Option<String>,
}
impl CommandV1 {
fn example() -> serde_json::Value {
serde_json::json!({
"name": "get_latest_article",
"outputType": "commandArticle",
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"dataConnectorCommand": {
"function": "latest_article"
},
"argumentMapping": {}
},
"graphql": {
"rootFieldName": "getLatestArticle",
"rootFieldKind": "Query"
},
"description": "Get the latest article",
})
}
}
#[derive(Default, Serialize, opendds_derive::OpenDd, Clone, Debug, PartialEq)]
/// Mapping of a comand or model argument name to the corresponding argument name used in the data connector.
/// The key of this object is the argument name used in the command or model and the value

View File

@ -26,13 +26,51 @@ pub struct DataConnectorName(pub Identifier);
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "DataConnectorLink"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "DataConnectorLink", example = "DataConnectorLink::example")
)]
/// Definition of a data connector, used to bring in sources of data and connect them to OpenDD models and commands.
pub enum DataConnectorLink {
V1(DataConnectorLinkV1),
}
impl DataConnectorLink {
fn example() -> serde_json::Value {
serde_json::json!({
"kind": "DataConnectorLink",
"version": "v1",
"definition": {
"name": "data_connector",
"url": {
"singleUrl": {
"value": "http://data_connector:8100"
}
},
"headers": {},
"schema": {
"version": "v0.1",
"schema": {
"scalar_types": {},
"object_types": {},
"collections": [],
"functions": [],
"procedures": []
},
"capabilities": {
"version": "0.1.0",
"capabilities": {
"query": {
"variables": {}
},
"mutation": {}
}
},
}
}
})
}
pub fn upgrade(self) -> DataConnectorLinkV1 {
match self {
DataConnectorLink::V1(v1) => v1,

View File

@ -44,10 +44,7 @@ impl Deref for HttpHeaders {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(
title = "DataConnectorLinkV1",
example = "DataConnectorLinkV1::example"
))]
#[opendd(json_schema(title = "DataConnectorLinkV1",))]
/// Definition of a data connector - version 1.
pub struct DataConnectorLinkV1 {
/// The name of the data connector.
@ -61,36 +58,3 @@ pub struct DataConnectorLinkV1 {
/// serving requests and the live schema of the data connector is not looked up.
pub schema: VersionedSchemaAndCapabilities,
}
impl DataConnectorLinkV1 {
fn example() -> serde_json::Value {
serde_json::json!({
"name": "data_connector",
"url": {
"singleUrl": {
"value": "http://data_connector:8100"
}
},
"headers": {},
"schema": {
"version": "v0.1",
"schema": {
"scalar_types": {},
"object_types": {},
"collections": [],
"functions": [],
"procedures": []
},
"capabilities": {
"version": "0.1.0",
"capabilities": {
"query": {
"variables": {}
},
"mutation": {}
}
},
}
})
}
}

View File

@ -32,12 +32,74 @@ impl_JsonSchema_with_OpenDd_for!(ModelName);
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "Model"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "Model", example = "Model::example")
)]
pub enum Model {
V1(ModelV1),
}
impl Model {
fn example() -> serde_json::Value {
serde_json::json!({
"kind": "Model",
"version": "v1",
"definition": {
"name": "Articles",
"objectType": "article",
"globalIdSource": true,
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"collection": "articles",
"argumentMapping": {}
},
"filterExpressionType": "Article_bool_exp",
"orderableFields": [
{
"fieldName": "article_id",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "title",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"orderByDirections": {
"enableAll": true
}
}
],
"graphql": {
"selectUniques": [
{
"queryRootField": "ArticleByID",
"uniqueIdentifier": [
"article_id"
],
"description": "Description for the select unique ArticleByID"
}
],
"selectMany": {
"queryRootField": "ArticleMany",
"description": "Description for the select many ArticleMany"
},
"orderByExpressionType": "Article_Order_By",
"apolloFederation": {
"entitySource": true
}
},
"description": "Description for the model Articles"
}
})
}
pub fn upgrade(self) -> ModelV1 {
match self {
Model::V1(v1) => v1,
@ -47,7 +109,7 @@ impl Model {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "ModelV1", example = "ModelV1::example"))]
#[opendd(json_schema(title = "ModelV1"))]
/// The definition of a data model.
/// A data model is a collection of objects of a particular type. Models can support one or more CRUD operations.
pub struct ModelV1 {
@ -74,63 +136,6 @@ pub struct ModelV1 {
pub description: Option<String>,
}
impl ModelV1 {
fn example() -> serde_json::Value {
serde_json::json!({
"name": "Articles",
"objectType": "article",
"globalIdSource": true,
"arguments": [],
"source": {
"dataConnectorName": "data_connector",
"collection": "articles",
"argumentMapping": {}
},
"filterExpressionType": "Article_bool_exp",
"orderableFields": [
{
"fieldName": "article_id",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "title",
"orderByDirections": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"orderByDirections": {
"enableAll": true
}
}
],
"graphql": {
"selectUniques": [
{
"queryRootField": "ArticleByID",
"uniqueIdentifier": [
"article_id"
],
"description": "Description for the select unique ArticleByID"
}
],
"selectMany": {
"queryRootField": "ArticleMany",
"description": "Description for the select many ArticleMany"
},
"orderByExpressionType": "Article_Order_By",
"apolloFederation": {
"entitySource": true
}
},
"description": "Description for the model Articles"
})
}
}
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "ModelSource", example = "ModelSource::example"))]

View File

@ -47,13 +47,49 @@ pub struct ArgumentPreset {
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "TypePermissions"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "TypePermissions", example = "TypePermissions::example")
)]
/// Definition of permissions for an OpenDD type.
pub enum TypePermissions {
V1(TypePermissionsV1),
}
impl TypePermissions {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "TypePermissions",
"version": "v1",
"definition": {
"typeName": "article",
"permissions": [
{
"role": "admin",
"output": {
"allowedFields": [
"article_id",
"author_id",
"title"
]
}
},
{
"role": "user",
"output": {
"allowedFields": [
"article_id",
"author_id"
]
}
}
]
}
}
)
}
pub fn upgrade(self) -> TypePermissionsV1 {
match self {
TypePermissions::V1(v1) => v1,
@ -63,7 +99,7 @@ impl TypePermissions {
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "TypePermissionsV1", example = "TypePermissionsV1::example"))]
#[opendd(json_schema(title = "TypePermissionsV1"))]
/// Definition of permissions for an OpenDD type.
pub struct TypePermissionsV1 {
/// The name of the type for which permissions are being defined. Must be an object type.
@ -72,37 +108,6 @@ pub struct TypePermissionsV1 {
pub permissions: Vec<TypePermission>,
}
impl TypePermissionsV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"typeName": "article",
"permissions": [
{
"role": "admin",
"output": {
"allowedFields": [
"article_id",
"author_id",
"title"
]
}
},
{
"role": "user",
"output": {
"allowedFields": [
"article_id",
"author_id"
]
}
}
]
}
)
}
}
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "TypePermission", example = "TypePermission::example"))]
@ -180,13 +185,50 @@ pub struct FieldPreset {
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "ModelPermissions"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "ModelPermissions", example = "ModelPermissions::example")
)]
/// Definition of permissions for an OpenDD model.
pub enum ModelPermissions {
V1(ModelPermissionsV1),
}
impl ModelPermissions {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "ModelPermissions",
"version": "v1",
"definition": {
"modelName": "Articles",
"permissions": [
{
"role": "admin",
"select": {
"filter": null
}
},
{
"role": "user",
"select": {
"filter": {
"fieldComparison": {
"field": "author_id",
"operator": "_eq",
"value": {
"sessionVariable": "x-hasura-user-id"
}
}
}
}
}
]
}
}
)
}
pub fn upgrade(self) -> ModelPermissionsV1 {
match self {
ModelPermissions::V1(v1) => v1,
@ -196,7 +238,7 @@ impl ModelPermissions {
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "ModelPermissionsV1", example = "ModelPermissionsV1::example"))]
#[opendd(json_schema(title = "ModelPermissionsV1"))]
/// Definition of permissions for an OpenDD model.
pub struct ModelPermissionsV1 {
/// The name of the model for which permissions are being defined.
@ -205,38 +247,6 @@ pub struct ModelPermissionsV1 {
pub permissions: Vec<ModelPermission>,
}
impl ModelPermissionsV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"modelName": "Articles",
"permissions": [
{
"role": "admin",
"select": {
"filter": null
}
},
{
"role": "user",
"select": {
"filter": {
"fieldComparison": {
"field": "author_id",
"operator": "_eq",
"value": {
"sessionVariable": "x-hasura-user-id"
}
}
}
}
}
]
}
)
}
}
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "ModelPermission", example = "ModelPermission::example"))]
@ -374,7 +384,7 @@ impl CommandPermission {
#[serde(rename_all = "camelCase")]
#[opendd(
as_versioned_with_definition,
json_schema(title = "CommandPermissions")
json_schema(title = "CommandPermissions", example = "CommandPermissions::example")
)]
/// Definition of permissions for an OpenDD command.
pub enum CommandPermissions {
@ -382,6 +392,28 @@ pub enum CommandPermissions {
}
impl CommandPermissions {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "CommandPermissions",
"version": "v1",
"definition": {
"commandName": "get_article_by_id",
"permissions": [
{
"role": "admin",
"allowExecution": true
},
{
"role": "user",
"allowExecution": true
}
]
}
}
)
}
pub fn upgrade(self) -> CommandPermissionsV1 {
match self {
CommandPermissions::V1(v1) => v1,
@ -391,10 +423,7 @@ impl CommandPermissions {
#[derive(Serialize, Clone, Debug, Eq, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(
title = "CommandPermissionsV1",
example = "CommandPermissionsV1::example"
))]
#[opendd(json_schema(title = "CommandPermissionsV1"))]
/// Definition of permissions for an OpenDD command.
pub struct CommandPermissionsV1 {
/// The name of the command for which permissions are being defined.
@ -403,26 +432,6 @@ pub struct CommandPermissionsV1 {
pub permissions: Vec<CommandPermission>,
}
impl CommandPermissionsV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"commandName": "get_article_by_id",
"permissions": [
{
"role": "admin",
"allowExecution": true
},
{
"role": "user",
"allowExecution": true
}
]
}
)
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]

View File

@ -182,13 +182,55 @@ impl RelationshipMapping {
#[derive(Serialize, Clone, Debug, PartialEq, Eq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "Relationship"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "Relationship", example = "Relationship::example")
)]
/// Definition of a relationship on an OpenDD type which allows it to be extended with related models or commands.
pub enum Relationship {
V1(RelationshipV1),
}
impl Relationship {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "Relationship",
"version": "v1",
"definition": {
"name": "Articles",
"source": "author",
"target": {
"model": {
"name": "Articles",
"subgraph": null,
"relationshipType": "Array"
}
},
"mapping": [
{
"source": {
"fieldPath": [
{
"fieldName": "author_id"
}
]
},
"target": {
"modelField": [
{
"fieldName": "author_id"
}
]
}
}
],
"description": "Articles written by an author"
}
}
)
}
pub fn upgrade(self) -> RelationshipV1 {
match self {
Relationship::V1(v1) => v1,
@ -198,7 +240,7 @@ impl Relationship {
#[derive(Serialize, Clone, Debug, PartialEq, Eq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "RelationshipV1", example = "RelationshipV1::example"))]
#[opendd(json_schema(title = "RelationshipV1"))]
/// Definition of a relationship on an OpenDD type which allows it to be extended with related models or commands.
pub struct RelationshipV1 {
/// The name of the relationship.
@ -216,40 +258,3 @@ pub struct RelationshipV1 {
/// If set, the deprecation status is added to the relationship field's graphql schema.
pub deprecated: Option<Deprecated>,
}
impl RelationshipV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"name": "Articles",
"source": "author",
"target": {
"model": {
"name": "Articles",
"subgraph": null,
"relationshipType": "Array"
}
},
"mapping": [
{
"source": {
"fieldPath": [
{
"fieldName": "author_id"
}
]
},
"target": {
"modelField": [
{
"fieldName": "author_id"
}
]
}
}
],
"description": "Articles written by an author"
}
)
}
}

View File

@ -265,12 +265,62 @@ pub struct ObjectTypeGraphQLConfiguration {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "ObjectType"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "ObjectType", example = "ObjectType::example")
)]
pub enum ObjectType {
V1(ObjectTypeV1),
}
impl ObjectType {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "ObjectType",
"version": "v1",
"definition": {
"name": "Author",
"fields": [
{
"name": "author_id",
"type": "Int!",
"description": "The id of the author"
},
{
"name": "first_name",
"type": "String",
"description": "The first name of the author"
},
{
"name": "last_name",
"type": "String",
"description": "The last name of the author"
}
],
"description": "An author of a book",
"globalIdFields": [
"author_id"
],
"graphql": {
"typeName": "Author"
},
"dataConnectorTypeMapping": [{
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"fieldMapping": {
"author_id": {
"column": {
"name": "id"
}
}
}
}]
}
}
)
}
pub fn upgrade(self) -> ObjectTypeV1 {
match self {
ObjectType::V1(v1) => v1,
@ -280,7 +330,7 @@ impl ObjectType {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "ObjectTypeV1", example = "ObjectTypeV1::example"))]
#[opendd(json_schema(title = "ObjectTypeV1"))]
/// Definition of a user-defined Open DD object type.
pub struct ObjectTypeV1 {
/// The name to give this object type, used to refer to it elsewhere in the metadata.
@ -307,51 +357,6 @@ pub struct ObjectTypeV1 {
pub data_connector_type_mapping: Vec<DataConnectorTypeMapping>,
}
impl ObjectTypeV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"name": "Author",
"fields": [
{
"name": "author_id",
"type": "Int!",
"description": "The id of the author"
},
{
"name": "first_name",
"type": "String",
"description": "The first name of the author"
},
{
"name": "last_name",
"type": "String",
"description": "The last name of the author"
}
],
"description": "An author of a book",
"globalIdFields": [
"author_id"
],
"graphql": {
"typeName": "Author"
},
"dataConnectorTypeMapping": [{
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"fieldMapping": {
"author_id": {
"column": {
"name": "id"
}
}
}
}]
}
)
}
}
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "DataConnectorTypeMapping"))]
@ -460,12 +465,29 @@ pub struct ScalarTypeGraphQLConfiguration {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(tag = "version", content = "definition")]
#[serde(rename_all = "camelCase")]
#[opendd(as_versioned_with_definition, json_schema(title = "ScalarType"))]
#[opendd(
as_versioned_with_definition,
json_schema(title = "ScalarType", example = "ScalarType::example")
)]
pub enum ScalarType {
V1(ScalarTypeV1),
}
impl ScalarType {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "ScalarType",
"version": "v1",
"name": "CustomString",
"graphql": {
"typeName": "CustomString"
},
"description": "A custom string type"
}
)
}
pub fn upgrade(self) -> ScalarTypeV1 {
match self {
ScalarType::V1(v1) => v1,
@ -475,7 +497,7 @@ impl ScalarType {
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "ScalarTypeV1", example = "ScalarTypeV1::example"))]
#[opendd(json_schema(title = "ScalarTypeV1"))]
/// Definition of a user-defined scalar type that that has opaque semantics.
pub struct ScalarTypeV1 {
/// The name to give this scalar type, used to refer to it elsewhere in the metadata.
@ -488,20 +510,6 @@ pub struct ScalarTypeV1 {
pub description: Option<String>,
}
impl ScalarTypeV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"name": "CustomString",
"graphql": {
"typeName": "CustomString"
},
"description": "A custom string type"
}
)
}
}
/// GraphQL configuration of a data connector scalar
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
@ -569,13 +577,54 @@ impl DataConnectorScalarRepresentationV1 {
#[serde(rename_all = "camelCase")]
#[opendd(
as_versioned_with_definition,
json_schema(title = "ObjectBooleanExpressionType")
json_schema(
title = "ObjectBooleanExpressionType",
example = "ObjectBooleanExpressionType::example"
)
)]
pub enum ObjectBooleanExpressionType {
V1(ObjectBooleanExpressionTypeV1),
}
impl ObjectBooleanExpressionType {
fn example() -> serde_json::Value {
serde_json::json!(
{
"kind": "ObjectBooleanExpressionType",
"version": "v1",
"definition": {
"name": "AuthorBoolExp",
"objectType": "Author",
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"comparableFields": [
{
"fieldName": "article_id",
"operators": {
"enableAll": true
}
},
{
"fieldName": "title",
"operators": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"operators": {
"enableAll": true
}
}
],
"graphql": {
"typeName": "Author_bool_exp"
}
}
}
)
}
pub fn upgrade(self) -> ObjectBooleanExpressionTypeV1 {
match self {
ObjectBooleanExpressionType::V1(v1) => v1,
@ -598,10 +647,7 @@ pub struct OperatorName(pub String);
#[derive(Serialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]
#[opendd(json_schema(
title = "ObjectBooleanExpressionTypeV1",
example = "ObjectBooleanExpressionTypeV1::example"
))]
#[opendd(json_schema(title = "ObjectBooleanExpressionTypeV1",))]
/// Definition of a type representing a boolean expression on an Open DD object type.
pub struct ObjectBooleanExpressionTypeV1 {
/// The name to give this object boolean expression type, used to refer to it elsewhere in the metadata.
@ -624,42 +670,6 @@ pub struct ObjectBooleanExpressionTypeV1 {
pub graphql: Option<ObjectBooleanExpressionTypeGraphQlConfiguration>,
}
impl ObjectBooleanExpressionTypeV1 {
fn example() -> serde_json::Value {
serde_json::json!(
{
"name": "AuthorBoolExp",
"objectType": "Author",
"dataConnectorName": "my_db",
"dataConnectorObjectType": "author",
"comparableFields": [
{
"fieldName": "article_id",
"operators": {
"enableAll": true
}
},
{
"fieldName": "title",
"operators": {
"enableAll": true
}
},
{
"fieldName": "author_id",
"operators": {
"enableAll": true
}
}
],
"graphql": {
"typeName": "Author_bool_exp"
}
}
)
}
}
/// GraphQL configuration of an Open DD boolean expression type.
#[derive(Serialize, Clone, Debug, PartialEq, Eq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")]