Search code examples
graphqlaws-amplify

Best practice for mailing addresses types


I am fairly new to GraphQL and i am writing a schema which will include companies and users. Each of these entities will have a mailing address associated with them. I am also using AWS Amplify to generate the resolvers and the DB (at least to get the project going).

  • I don't intend to retrieve an address separate from its user/company
  • Want to make the schema as modular as possible without repeating information unnecessarily

Here's an abbreviated version of what I started

type Address {
  id: ID!
  streetAddress1: String!
  streetAddress2: String
  city: String!
  state: String!
  zipCode: String!
  country: String!
  coordinates: String
}

type Company 
{
  id: ID!
  name: String!
  address: Address!
  ...
}

My question is whether it is best to have the address as a separate type in my schema or to lump each of the company/user types with their own address? These are my concerns though

  • Separating address and entity increases complexity of the business logic and/or mutations.
  • In essence, turning the CRUD operations transactional in nature so that both user and address are mutated/queried.

Solution

  • Figured I would use an Address type without @model annotation and no @connection from the types that require it.