Skip to content

Commit

Permalink
fix: improve join table identification
Browse files Browse the repository at this point in the history
  • Loading branch information
Hein Jeong committed Feb 17, 2023
1 parent adb5941 commit 4eb0744
Show file tree
Hide file tree
Showing 3 changed files with 462 additions and 28 deletions.
381 changes: 381 additions & 0 deletions packages/codegen-ui/lib/__tests__/__utils__/mock-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2681,3 +2681,384 @@ export const schemaWithHasManyBelongsTo: Schema = {
codegenVersion: '3.3.5',
version: 'f2f8e885f81740e5be20b201c850fa05',
};

/**
type Box @model {
id: ID!
name: String
crateID: ID! @index(name: "byCrate")
Crate: Crate @belongsTo(fields: ["crateID"])
}
type Crate @model {
id: ID!
destination: String
Boxes: [Box] @hasMany(indexName: "byCrate", fields: ["id"])
}
*/
export const schemaWithoutJoinTables: Schema = {
models: {
User: {
name: 'User',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
Entries: {
name: 'Entries',
isArray: true,
type: {
model: 'Entry',
},
isRequired: false,
attributes: [],
isArrayNullable: true,
association: {
connectionType: 'HAS_MANY',
associatedWith: ['User'],
},
},
Images: {
name: 'Images',
isArray: true,
type: {
model: 'Image',
},
isRequired: false,
attributes: [],
isArrayNullable: true,
association: {
connectionType: 'HAS_MANY',
associatedWith: ['User'],
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'Users',
attributes: [
{
type: 'model',
properties: {},
},
],
},
Entry: {
name: 'Entry',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
userID: {
name: 'userID',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
User: {
name: 'User',
isArray: false,
type: {
model: 'User',
},
isRequired: false,
attributes: [],
association: {
connectionType: 'BELONGS_TO',
targetNames: ['userID'],
},
},
Images: {
name: 'Images',
isArray: true,
type: {
model: 'Image',
},
isRequired: false,
attributes: [],
isArrayNullable: true,
association: {
connectionType: 'HAS_MANY',
associatedWith: ['Entry'],
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'Entries',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
name: 'byUser',
fields: ['userID'],
},
},
],
},
Image: {
name: 'Image',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
userID: {
name: 'userID',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
entryID: {
name: 'entryID',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
User: {
name: 'User',
isArray: false,
type: {
model: 'User',
},
isRequired: true,
attributes: [],
association: {
connectionType: 'BELONGS_TO',
targetNames: ['userID'],
},
},
Entry: {
name: 'Entry',
isArray: false,
type: {
model: 'Entry',
},
isRequired: true,
attributes: [],
association: {
connectionType: 'BELONGS_TO',
targetNames: ['entryID'],
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'Images',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
name: 'byUser',
fields: ['userID'],
},
},
{
type: 'key',
properties: {
name: 'byEntry',
fields: ['entryID'],
},
},
],
},
Box: {
name: 'Box',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
name: {
name: 'name',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
crateID: {
name: 'crateID',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
Crate: {
name: 'Crate',
isArray: false,
type: {
model: 'Crate',
},
isRequired: false,
attributes: [],
association: {
connectionType: 'BELONGS_TO',
targetNames: ['crateID'],
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'Boxes',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
name: 'byCrate',
fields: ['crateID'],
},
},
],
},
Crate: {
name: 'Crate',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
destination: {
name: 'destination',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
Boxes: {
name: 'Boxes',
isArray: true,
type: {
model: 'Box',
},
isRequired: false,
attributes: [],
isArrayNullable: true,
association: {
connectionType: 'HAS_MANY',
associatedWith: ['Crate'],
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: false,
attributes: [],
isReadOnly: true,
},
},
syncable: true,
pluralName: 'Crates',
attributes: [
{
type: 'model',
properties: {},
},
],
},
},
enums: {},
nonModels: {},
codegenVersion: '3.3.5',
version: '925d97d5ee6e402764bce3a9c0e546c1',
};
Loading

0 comments on commit 4eb0744

Please sign in to comment.