aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 78 forks source link

Custom query depends on built input, ModelFooConnection types #421

Open at0mat opened 5 years ago

at0mat commented 5 years ago

Note: If your question is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum

Which Category is your question related to? API

What AWS Services are you utilizing? AppSync, DynamoDB, Elastic Search, Cognito

Provide additional details e.g. code snippets In schema.graphql :

type Location {
  lat: Float
  lon: Float
}

type Address @model @searchable {
  id: ID!
  civicNumber: String
  fullAddress: String!
  localityName: String
  localityType: String
  location: Location
  provinceCode: String
  rawJSON: String
  siteID: String
  streetDirection: String
  streetName: String
  streetType: String
  unitNumber: String
  noContact: Boolean
  noSolicit: Boolean
}

input BoundsInput {
  nw: LocationInput
  se: LocationInput
}

input LocationInput {
  lat: Float
  lon: Float
}

enum SearchableSortDirection {# Duplicate from build copy
  asc
  desc
}

enum SearchableAddressSortableFields {# Duplicate from build copy
  id
  civicNumber
  fullAddress
  localityName
  localityType
  provinceCode
  rawJSON
  siteID
  streetDirection
  streetName
  streetType
  unitNumber
  noContact
  noSolicit
}

input SearchableAddressSortInput  {# Duplicate from build copy
  field: SearchableAddressSortableFields
  direction: SearchableSortDirection
}

type ModelAddressConnection { # Duplicate from build copy
  items: [Address]
  nextToken: String
}

type Query {
  addressInBounds(bounds: BoundsInput!, sort: SearchableAddressSortInput, limit: Int, nextToken: Int): ModelAddressConnection
  nearbyAddresss(location: LocationInput!, km: Int, sort: SearchableAddressSortInput, limit: Int, nextToken: Int): ModelAddressConnection
}

input SearchableAddressSortInput, type ModelAddressConnection along with enums SearchableSortDirection, SearchableAddressSortableFields have been manually copied from the codegen created build directory copy of the schema as a workaround.

If I don't copy the type definitions, when running amplify push I receive: Type "SearchableAddressSortableFields" not found in document.

Is there a way to make custom query resources without having to duplicate these auto generated input, type, enum statements?

mikeparisstuff commented 5 years ago

As of writing the input document(s) are expected to be a full schema. It would be possible to allow referencing generated types but this would need time for design and implementation. In the meantime, copying the type definitions into your own schema is likely the best solution. Marking this as a feature request.

mgarabedian commented 3 years ago

I have been trying to solve this problem myself. Copying the generated schema over is constantly causing me problems. Has this since been resolved in any way?

txmazing commented 2 years ago

Any better solution yet?

danrivett commented 1 year ago

I ran into this today too creating a custom mutation that wants to reference a generated input type to be used as a nested field as I want to create a composite action that does two actions in one operation.

Copying generated input types is really not a good solution (even if the only workaround currently) as they can very easily get out of sync, plus it's not DRY obviously.

Also this issue is tagged with graphql-transformer-v1 but we're using the v2 transformer, and the issue is also present there for us.