Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main to gen2 #808

Merged
merged 8 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .codebuild/e2e_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,25 @@ batch:
depend-on:
- publish_to_local_registry
- identifier: >-
l_build_app_ts_graphql_generator_app_uninitialized_project_codegen_js_uninitialized_project_modelgen_android
l_build_app_ts_graphql_generator_app_push_codegen_admin_modelgen_uninitialized_project_codegen_js
buildspec: .codebuild/run_e2e_tests.yml
env:
compute-type: BUILD_GENERAL1_LARGE
variables:
TEST_SUITE: >-
src/__tests__/build-app-ts.test.ts|src/__tests__/graphql-generator-app.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts|src/__tests__/uninitialized-project-modelgen-android.test.ts
src/__tests__/build-app-ts.test.ts|src/__tests__/graphql-generator-app.test.ts|src/__tests__/push-codegen-admin-modelgen.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts
CLI_REGION: ap-southeast-1
DISABLE_ESLINT_PLUGIN: true
depend-on:
- publish_to_local_registry
- identifier: >-
l_uninitialized_project_modelgen_flutter_uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
l_uninitialized_project_modelgen_android_uninitialized_project_modelgen_flutter_uninitialized_project_modelgen_ios_uninitialize
buildspec: .codebuild/run_e2e_tests.yml
env:
compute-type: BUILD_GENERAL1_LARGE
variables:
TEST_SUITE: >-
src/__tests__/uninitialized-project-modelgen-flutter.test.ts|src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
src/__tests__/uninitialized-project-modelgen-android.test.ts|src/__tests__/uninitialized-project-modelgen-flutter.test.ts|src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
CLI_REGION: ap-southeast-2
depend-on:
- publish_to_local_registry
Expand Down Expand Up @@ -252,30 +252,30 @@ batch:
- publish_to_local_registry
- build_windows
- identifier: >-
w_build_app_ts_graphql_generator_app_uninitialized_project_codegen_js_uninitialized_project_modelgen_android
w_build_app_ts_graphql_generator_app_push_codegen_admin_modelgen_uninitialized_project_codegen_js
buildspec: .codebuild/run_e2e_tests_windows.yml
env:
compute-type: BUILD_GENERAL1_LARGE
image: $WINDOWS_IMAGE_2019
type: WINDOWS_SERVER_2019_CONTAINER
variables:
TEST_SUITE: >-
src/__tests__/build-app-ts.test.ts|src/__tests__/graphql-generator-app.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts|src/__tests__/uninitialized-project-modelgen-android.test.ts
src/__tests__/build-app-ts.test.ts|src/__tests__/graphql-generator-app.test.ts|src/__tests__/push-codegen-admin-modelgen.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts
CLI_REGION: us-east-1
DISABLE_ESLINT_PLUGIN: true
depend-on:
- publish_to_local_registry
- build_windows
- identifier: >-
w_uninitialized_project_modelgen_flutter_uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
w_uninitialized_project_modelgen_android_uninitialized_project_modelgen_flutter_uninitialized_project_modelgen_ios_uninitialize
buildspec: .codebuild/run_e2e_tests_windows.yml
env:
compute-type: BUILD_GENERAL1_LARGE
image: $WINDOWS_IMAGE_2019
type: WINDOWS_SERVER_2019_CONTAINER
variables:
TEST_SUITE: >-
src/__tests__/uninitialized-project-modelgen-flutter.test.ts|src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
src/__tests__/uninitialized-project-modelgen-android.test.ts|src/__tests__/uninitialized-project-modelgen-flutter.test.ts|src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
CLI_REGION: us-east-1
depend-on:
- publish_to_local_registry
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/closed-issue-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Closed Issue Message
on:
issues:
types: [closed]
jobs:
auto_comment:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/closed-issue-message@v1
with:
# These inputs are both required
repo-token: '${{ secrets.GITHUB_TOKEN }}'
message: |
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"eslint.packageManager": "yarn",
"eslint.quiet": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"jest.enableInlineErrorMessages": true,
"jest.showCoverageOnLoad": true,
Expand Down
262 changes: 262 additions & 0 deletions README-relationships.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
# Modeling relationships in the introspection schema

## Background

The Model Introspection Schema (MIS) is an intermediate representation of the GraphQL model that includes Amplify annotations. It is different
from the standard [GraphQL introspection schema](https://graphql.org/learn/introspection/) in that it includes relationship information, not
just type information.

> **NOTE:** The MIS is an internal implementation detail of the Amplify API plugin. It should not be used in a customer application.

## Sample

Given a schema like

```graphql
type Primary @model @auth(rules: [{ allow: public, operations: [read] }, { allow: owner }]) {
id: ID! @primaryKey
relatedMany: [RelatedMany] @hasMany(references: "primaryId")
relatedOne: RelatedOne @hasOne(references: "primaryId")
}

type RelatedMany @model @auth(rules: [{ allow: public, operations: [read] }, { allow: owner }]) {
id: ID! @primaryKey
primaryId: ID!
primary: Primary @belongsTo(references: "primaryId")
}

type RelatedOne @model @auth(rules: [{ allow: public, operations: [read] }, { allow: owner }]) {
id: ID! @primaryKey
primaryId: ID!
primary: Primary @belongsTo(references: "primaryId")
}
```

the MIS (abridged to show relationship information only) looks like:

```json
{
"version": 1,
"models": {
"Primary": {
"name": "Primary",
"fields": {
"relatedMany": {
"name": "relatedMany",
"isArray": true,
"type": {
"model": "RelatedMany"
},
"isRequired": false,
"attributes": [],
"isArrayNullable": true,
"association": {
"connectionType": "HAS_MANY",
"associatedWith": ["primaryId"]
}
},
"relatedOne": {
"name": "relatedOne",
"isArray": false,
"type": {
"model": "RelatedOne"
},
"isRequired": false,
"attributes": [],
"association": {
"connectionType": "HAS_ONE",
"associatedWith": ["primaryId"],
}
}
}
},
"RelatedMany": {
"name": "RelatedMany",
"fields": {
"primary": {
"name": "primary",
"isArray": false,
"type": {
"model": "Primary"
},
"isRequired": false,
"attributes": [],
"association": {
"connectionType": "BELONGS_TO",
"targetNames": ["primaryId"]
}
},
"primaryId": {
"name": "primaryId",
"isArray": false,
"type": "ID",
"isRequired": false,
"attributes": []
}
}
},
"RelatedOne": {
"name": "RelatedOne",
"fields": {
"primary": {
"name": "primary",
"isArray": false,
"type": {
"model": "Primary"
},
"isRequired": false,
"attributes": [],
"association": {
"connectionType": "BELONGS_TO",
"targetNames": ["primaryId"]
}
},
"primaryId": {
"name": "primaryId",
"isArray": false,
"type": "ID",
"isRequired": false,
"attributes": []
}
}
}
}
}
```

## Glossary

* **Associated type** - In a field decorated with a `@hasMany`, `@hasOne`, or `@belongsTo` directive, the model “pointed to” by the directive. In the sample schema:
* `Related` is the **associated type** for the `@hasMany` directive on `Primary.related`
* `Primary` is the **associated type** for the `@belongsTo` directive on `Related.primary`
* **Association field** - See **Connection field**
* **Connection field** - In any model type, the field that is decorated with a `@hasMany`, `@hasOne`, or `@belongsTo` directive. In the sample schema:
* `Primary.related` is the **connection field** in the `Primary` model, for the relationship `Primary -> Related` defined by the `@hasMany` on `Primary.related` and the `@belongsTo` on `Related.primary`
* `Related.primary` is the **connection field** in the `Related` model, for the relationship `Primary -> Related` defined by the `@hasMany` on `Primary.related` and the `@belongsTo` on `Related.primary`
* **Source type** - In a field decorated with a `@hasMany`, `@hasOne`, or `@belongsTo` directive, the model containing the directive. In the sample schema:
* `Primary` is the **source type** for the `@hasMany` directive on `Primary.related`
* `Related` is the **source type** for the `@belongsTo` directive on `Related.primary`

## Structure

Relationships are modeled in an `association` structure in the MIS. The `association` attribute must belong to a `@model` field, not a field of non-model type, enum, input, or custom query/mutation.

Here are the relevant types to define the association structure. Note that this is a simplified rendition of the JSON/JavaScript version of the MIS. Other platforms may represent the MIS differently. The full definition is in [source code](./appsync-modelgen-plugin/src/utils/process-connections.ts);

```ts
enum CodeGenConnectionType {
HAS_ONE = 'HAS_ONE',
BELONGS_TO = 'BELONGS_TO',
HAS_MANY = 'HAS_MANY',
}

type CodeGenConnectionTypeBase = {
kind: CodeGenConnectionType;
connectedModel: CodeGenModel;
// ^-- Type not shown
};

type CodeGenFieldConnectionBelongsTo = CodeGenConnectionTypeBase & {
kind: CodeGenConnectionType.BELONGS_TO;
targetNames: string[];
}

type CodeGenFieldConnectionHasOne = CodeGenConnectionTypeBase & {
kind: CodeGenConnectionType.HAS_ONE;
associatedWith: CodeGenField[];
// ^-- Type not shown -- rendered in MIS as a string array
targetNames: string[];
}

export type CodeGenFieldConnectionHasMany = CodeGenConnectionTypeBase & {
kind: CodeGenConnectionType.HAS_MANY;
associatedWith: CodeGenField[];
// ^-- Type not shown -- rendered in MIS as a string array
}
```

Considering a snippet of the above sample:

```json
"models": {
"Primary": {
"name": "Primary",
"fields": {
"relatedMany": {
"name": "relatedMany",
"isArray": true,
"type": {
"model": "RelatedMany"
},
"isRequired": false,
"attributes": [],
"isArrayNullable": true,
"association": {
"connectionType": "HAS_MANY",
"associatedWith": ["primaryId"]
}
},
...
"RelatedMany": {
"name": "RelatedMany",
"fields": {
"primary": {
"name": "primary",
"isArray": false,
"type": {
"model": "Primary"
},
"isRequired": false,
"attributes": [],
"association": {
"connectionType": "BELONGS_TO",
"targetNames": ["primaryId"]
}
},
"primaryId": {
"name": "primaryId",
"isArray": false,
"type": "ID",
"isRequired": false,
"attributes": []
}
```

- `models.Primary` - A type definition. The **source type** for any `association`s defined in this model.
- `models.Primary.fields.relatedMany` - The **association field**/**connection field**
- `models.Primary.fields.relatedMany.type` - The **associated type** for this relationship. This must be a `@model`.
- `models.Primary.fields.relatedMany.association` - The structure containing the data needed to navigate the relationship with the associated type
- `models.Primary.fields.relatedMany.association.connectionType` - The kind of relationship (has one, has many, belongs to) this **source type** has with the associated type
- `models.Primary.fields.relatedMany.association.associatedWith` - A list of fields on the **associated type** that hold the primary key of the **source** record. This is an array so we can support composite primary keys.
- `models.RelatedMany` - A type definition. The **source type** for any `association`s defined in this model.
- `models.RelatedMany.fields.primary.association.targetNames` - A list of fields on the **source type** (that is, the current type) that hold the primary key of the **associated** record. This is an array so we can support composite primary keys.
- `models.RelatedMany.fields.primaryId` - The field pointed to by `targetNames` above, containing the primary key of the **associated** record for the `RelatedOne.primary` relationship.


## Navigating relationships

We will describe the steps to resolve the record in pseudo-sql

### From source record to associated record

* If the source model has an `associatedWith` but no `targetNames`:
```
SELECT *
FROM <associated type>
WHERE <associatedWith fields> = <source type>.primaryKey
```
* If the source model has an `associatedWith` AND `targetNames`:
```
SELECT *
FROM <associated type>
WHERE <associatedWith fields> = <source type>.<targetNames fields>
```
* If the source model has a `targetNames` but no `associatedWith`:
```
SELECT *
FROM <associated type>
WHERE <source type>.<targetNames fields> = <associated type>.primaryKey
```



2 changes: 1 addition & 1 deletion dependency_licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Apache License

-----

The following software may be included in this product: @aws-amplify/graphql-schema-test-library, @aws-amplify/graphql-transformer-interfaces, graphql-mapping-template, graphql-transformer-common, graphql-transformer-core. A copy of the source code may be downloaded from https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-schema-test-library), https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-transformer-interfaces), https://github.com/aws-amplify/amplify-category-api.git (graphql-mapping-template), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-common), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-core). This software contains the following license and notice below:
The following software may be included in this product: @aws-amplify/graphql-directives, @aws-amplify/graphql-schema-test-library, @aws-amplify/graphql-transformer-interfaces, graphql-mapping-template, graphql-transformer-common, graphql-transformer-core. A copy of the source code may be downloaded from https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-directives), https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-schema-test-library), https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-transformer-interfaces), https://github.com/aws-amplify/amplify-category-api.git (graphql-mapping-template), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-common), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-core). This software contains the following license and notice below:

Apache License
Version 2.0, January 2004
Expand Down
6 changes: 6 additions & 0 deletions packages/amplify-codegen-e2e-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.6.4](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/amplify-codegen-e2e-core@1.6.3...@aws-amplify/amplify-codegen-e2e-core@1.6.4) (2024-04-03)

### Bug Fixes

- process input object, union and interface metadata in model introspection schema codegen ([#795](https://github.com/aws-amplify/amplify-codegen/issues/795)) ([73e4520](https://github.com/aws-amplify/amplify-codegen/commit/73e4520e8f3bbd63d6b123a5c977c415df443905))

## [1.6.3](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/amplify-codegen-e2e-core@1.6.2...@aws-amplify/amplify-codegen-e2e-core@1.6.3) (2023-12-11)

**Note:** Version bump only for package @aws-amplify/amplify-codegen-e2e-core
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-codegen-e2e-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/amplify-codegen-e2e-core",
"version": "1.6.3",
"version": "1.6.4",
"description": "",
"repository": {
"type": "git",
Expand Down
Loading
Loading