<aside> 📌 This style guide is publicly accessible, linked to from the engineering site.

</aside>

Principles and general guidelines


GraphQL Type System

We should generally be using the GraphQL type system as much as possible to model our data. This documents what is possible and what isn't, and also allows client languages that have stronger type systems to depend on the GraphQL schema to enforce correct usage at compile time.

General tips

Example

# Pseudo code

# Naive implementation
class PaymentMethod(ObjectType):
    card_token = String(required=False)
    paypal_token = String(required=False)
    method_type = Enum(('card', 'paypal'), required=True)

# This uses two optional fields for the different token types.
# This means it's technically possible to have a method:
#   PaymentMethod(method_type='card', card_token=None, paypal_token='tok_xxx')
# which is invalid.

# A better way to implement this would be to use a GraphQL Union instead
# of the enumeration of types, and make the token strings required.

class PayPalMethod(ObjectType):
    paypal_token = String(required=True)

class CardMethod(ObjectType):
    card_token = String(required=True)

class PaymentMethod(Union):
    class Meta:
        types = (PayPalMethod, CardMethod)