Skip to content

Commit

Permalink
Merge pull request #677 from gadget-inc/typesafe-recursive-metadata
Browse files Browse the repository at this point in the history
typesafe recursive metadata
  • Loading branch information
infiton authored Oct 21, 2024
2 parents dc5defb + 6cbefce commit af2b74e
Show file tree
Hide file tree
Showing 36 changed files with 5,832 additions and 3,358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,167 @@ describeForEachAutoAdapter("AutoForm - FindBy object parameters", ({ name, adapt
const uniqueFieldsMainModelMetadata = {
data: {
gadgetMeta: {
modelAndRelatedModels: [
{
name: "Main model",
apiIdentifier: "mainModel",
defaultRecord: {
__typename: "UniqueFieldsMainModel",
},
fields: [
{
name: "Unique string",
apiIdentifier: "uniqueString",
fieldType: "String",
requiredArgumentForInput: false,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "String",
validations: [
{
__typename: "GadgetGenericFieldValidation",
name: "Uniqueness",
specID: "gadget/validation/unique",
},
],
},
},
{
name: "Unique email",
apiIdentifier: "uniqueEmail",
fieldType: "Email",
requiredArgumentForInput: false,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "Email",
validations: [
{
__typename: "GadgetGenericFieldValidation",
name: "Uniqueness",
specID: "gadget/validation/unique",
},
],
},
},
{
name: "Unique belongs to",
apiIdentifier: "uniqueBelongsTo",
fieldType: "BelongsTo",
requiredArgumentForInput: false,
sortable: false,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetBelongsToConfig",
fieldType: "BelongsTo",
validations: [
{
__typename: "GadgetGenericFieldValidation",
name: "Uniqueness",
specID: "gadget/validation/unique",
},
],
relatedModel: {
key: "RK96To6wLTyn",
apiIdentifier: "parentModel",
namespace: ["uniqueFields"],
defaultDisplayField: {
name: "Parent unique string",
apiIdentifier: "parentUniqueString",
fieldType: "String",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
},
},
{
name: "Non unique string",
apiIdentifier: "nonUniqueString",
fieldType: "String",
requiredArgumentForInput: false,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "String",
validations: [],
},
},
{
name: "Child model entries",
apiIdentifier: "childModelEntries",
fieldType: "HasMany",
requiredArgumentForInput: false,
sortable: false,
filterable: false,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetHasManyConfig",
fieldType: "HasMany",
validations: [],
isJoinModelHasManyField: false,
relatedModel: {
key: "ZOw07DfjlSXQ",
apiIdentifier: "childModel",
namespace: ["uniqueFields"],
defaultDisplayField: {
name: "Alias",
apiIdentifier: "alias",
fieldType: "String",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseField: {
apiIdentifier: "mainModelParent",
__typename: "GadgetModelField",
},
},
},
],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
{
key: "RK96To6wLTyn",
apiIdentifier: "parentModel",
namespace: ["uniqueFields"],
defaultDisplayField: {
name: "Parent unique string",
apiIdentifier: "parentUniqueString",
fieldType: "String",
__typename: "GadgetModelField",
},
fields: [],
__typename: "GadgetModel",
},
{
key: "ZOw07DfjlSXQ",
apiIdentifier: "childModel",
namespace: ["uniqueFields"],
defaultDisplayField: {
name: "Alias",
apiIdentifier: "alias",
fieldType: "String",
__typename: "GadgetModelField",
},
fields: [],
__typename: "GadgetModel",
},
],
model: {
name: "Main model",
apiIdentifier: "mainModel",
Expand Down Expand Up @@ -216,6 +377,12 @@ const uniqueFieldsMainModelMetadata = {
],
__typename: "GadgetAction",
},
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
__typename: "GadgetApplicationMeta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,119 @@ describeForEachAutoAdapter("AutoForm - HasManyThrough fields", ({ name, adapter:
const modelActionMetadataResponse = {
data: {
gadgetMeta: {
modelAndRelatedModels: [
{
name: "Base model",
apiIdentifier: "baseModel",
defaultRecord: {
__typename: "HasManyThroughBaseModel",
},
fields: [
{
name: "Base model name",
apiIdentifier: "baseModelName",
fieldType: "String",
requiredArgumentForInput: false,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "String",
validations: [],
},
},
{
name: "Joiner models",
apiIdentifier: "joinerModels",
fieldType: "HasMany",
requiredArgumentForInput: false,
sortable: false,
filterable: false,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetHasManyConfig",
fieldType: "HasMany",
validations: [],
isJoinModelHasManyField: true,
relatedModel: {
key: "tJDsf_FvYqsi",
apiIdentifier: "joinerModel",
namespace: ["hasManyThrough"],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseField: {
apiIdentifier: "joinerBelongsToBase",
__typename: "GadgetModelField",
},
},
},
{
name: "Base model hmt field",
apiIdentifier: "baseModelHmtField",
fieldType: "HasManyThrough",
requiredArgumentForInput: false,
sortable: false,
filterable: false,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetHasManyThroughConfig",
fieldType: "HasManyThrough",
validations: [],
relatedModel: {
key: "Oss4sCDW-DJU",
apiIdentifier: "siblingModel",
namespace: ["hasManyThrough"],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseField: {
apiIdentifier: "siblingModelHmtField",
__typename: "GadgetModelField",
},
joinModel: {
key: "tJDsf_FvYqsi",
apiIdentifier: "joinerModel",
namespace: ["hasManyThrough"],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseJoinModelField: {
apiIdentifier: "joinerBelongsToBase",
__typename: "GadgetModelField",
},
inverseRelatedModelField: {
apiIdentifier: "joinerBelongsToSibling",
__typename: "GadgetModelField",
},
},
},
],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
],
model: {
name: "Base model",
apiIdentifier: "baseModel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,85 @@ describeForEachAutoAdapter("AutoForm - Upsert Action", ({ name, adapter: { AutoF
const upsertModelActionMetadataResponse = {
data: {
gadgetMeta: {
modelAndRelatedModels: [
{
name: "Widget",
apiIdentifier: "widget",
defaultRecord: {
name: "",
description: {
markdown: "",
},
category: [],
__typename: "Widget",
},
fields: [
{
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
requiredArgumentForInput: false,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "ID",
validations: [],
},
},
{
name: "Name",
apiIdentifier: "name",
fieldType: "String",
requiredArgumentForInput: true,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "String",
validations: [
{
__typename: "GadgetGenericFieldValidation",
name: "Required",
specID: "gadget/validation/required",
},
],
},
},
{
name: "Inventory count",
apiIdentifier: "inventoryCount",
fieldType: "Number",
requiredArgumentForInput: true,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetNumberConfig",
fieldType: "Number",
validations: [
{
__typename: "GadgetRangeFieldValidation",
name: "Number range",
specID: "gadget/validation/number-range",
min: 0,
max: null,
},
{
__typename: "GadgetGenericFieldValidation",
name: "Required",
specID: "gadget/validation/required",
},
],
decimals: null,
},
},
],
__typename: "GadgetModel",
},
],
model: {
name: "Widget",
apiIdentifier: "widget",
Expand Down
Loading

0 comments on commit af2b74e

Please sign in to comment.