gqlify icon indicating copy to clipboard operation
gqlify copied to clipboard

Data model relationship generation

Open alexandrethsilva opened this issue 6 years ago • 0 comments

Describe the bug A Type containing multiple fields that contain relationships on the Data Model create a single expected Input Type in all the fields of said Type, as below:

To Reproduce Steps to reproduce the behavior:

  1. Given the following data model:
  type UserContact {
    email: String
    telephone: String
  }

  type UserSession {
    session_start_timestamp: Float
    session_end_timestamp: Float
  }

  type Article @GQLifyModel(dataSource: "firestore", key: "articles") {
    id: ID! @unique @autoGen
    title: String
    content: String
  }

  type Video @GQLifyModel(dataSource: "firestore", key: "videos") {
    id: ID! @unique @autoGen
    title: String
    url: String
  }

  type User @GQLifyModel(dataSource: "firestore", key: "users") {
    id: ID! @unique @autoGen
    user_contact: UserContact!
    user_sessions: [UserSession!]!
    bookmarked_articles: [Article!]! @relation(name: "UserOnArticles")
    bookmarked_videos: [Video!]! @relation(name: "UserOnVideos")
  }
  1. Open the schema generated by GQLify
  2. Observe that the inputFields of both bookmarked_articles and bookmarked_videos refer to UserCreateManyInput
{
    "name": "bookmarked_articles",
    "description": "",
    "type": {
      "kind": "INPUT_OBJECT",
      "name": "UserCreateManyInput",
      "ofType": null
    },
    "defaultValue": null
  }
{
    "name": "bookmarked_videos",
    "description": "",
    "type": {
      "kind": "INPUT_OBJECT",
      "name": "UserCreateManyInput",
      "ofType": null
    },
    "defaultValue": null
  }
  1. Look at UserCreateManyInput and observe the inputFields of create and connect
{
  "kind": "INPUT_OBJECT",
  "name": "UserCreateManyInput",
  "description": "",
  "fields": null,
  "inputFields": [
    {
      "name": "create",
      "description": "",
      "type": {
        "kind": "LIST",
        "name": null,
        "ofType": {
          "kind": "INPUT_OBJECT",
          "name": "VideoCreateInput",
          "ofType": null
        }
      },
      "defaultValue": null
    },
    {
      "name": "connect",
      "description": "",
      "type": {
        "kind": "LIST",
        "name": null,
        "ofType": {
          "kind": "INPUT_OBJECT",
          "name": "VideoWhereUniqueInput",
          "ofType": null
        }
      },
      "defaultValue": null
    }
  ],
  "interfaces": null,
  "enumValues": null,
  "possibleTypes": null
}
  1. They refer, respectively, to VideoCreateInput and VideoWhereUniqueInput.

Expected behavior Each relationship should create a unique inputField value, e.g. UserCreateManyArticlesInput and UserCreateManyVideosInput, where each refer to the correct input shape.

Desktop (please complete the following information):

  • OS: OSX
  • Version 10.14.2

Additional context No matter how many field relationships you have above 1, the Input Object referred to by UserCreateManyInput is always the last field. In the example above, if I were to add a third relation field e.g. bookmarked_xs, the UserCreateManyInput would then start referring to XCreateInput and XWhereUniqueInput.

alexandrethsilva avatar Apr 08 '19 14:04 alexandrethsilva