Objects (type)#

Meta: lead with "a type declares both a type and its prototype constructor." That's the unusual thing. Cross-link to Mutation and copy-on-write — don't try to explain CoW here.

Declaration#

type Person {
  name: String!
  age: Int! = 0

  greet: String! {
    "hi, I'm " + name
  }
}

Public vs. private members#

Implicit constructor#

Person("Alice", age: 30)
Person(name: "Alice")

Zero-arg auto-construction#

Explicit constructor: new#

type Greeter {
  greeting: String!

  new(name: String!) {
    self.greeting = "hello, " + name
    self
  }
}

self#

Computed fields#

fullName: String! { firstName + " " + lastName }

Implements#

type Person implements Named & Identifiable { name: String!, id: String! }

Forward references#

Meta: user-defined types and imported GraphQL input types share the same Type(args) construction syntax. Schema input types are constructed exactly like local types: CreateUserInput(name: "Alice", email: "...") passed as Mutation.createUser(input: ...). See GraphQL interop.