@embedded

Specifies that the type should be embedded within any types referring to this type.

Location

Types.

Arguments

None.

Description

The @embedded directive marks the annotated as an embedded type. Embedded types do not have their own associated collection; the data for an embedded type is stored within the parent type.

Example

Given the following GraphQL schema:

type User {
  name: String
  address: Address
}

type Address @embedded {
  street: String!
  city: String!
  zipCode: String!
}

You could create a user and address with the following mutation:

mutation {
  createUser(
    data: {
      name: "Mary"
      address: {
        street: "Market street, 1023"
        city: "San Francisco"
        zipCode: "91044"
      }
    }
  ) {
    _id
  }
}

The resulting document within FaunaDB would look like:

Get(Ref(Collection("User")
{ ref: Ref(Collection("User"), "235155496629174791"),
  ts: 1560520607525000,
  data:
   { name: 'Mary',
     address:
      { street: 'Market street, 1023',
        city: 'San Francisco',
        zipCode: '91044' } } }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!