GraphQL

GraphQL

POST /graphql

{
  event(id: 1) {
    name
    event_posts {
      body
      kind
      created_by { 
        name
      }
    }
  }
}
{
  "data": {
    "event": {
      "name": "Weekend Services",
      "event_posts": [
        {
          "body": "PiCO approved the request ...",
          "kind": "SYSTEM",
          "created_by": {
            "name": "PiCO Das Robot"
          }
        },
        { 
          ... 
        }
      ]
    }
  }
}

GraphiQL

Strongly typed, self-documenting

Suggested Resources

Suggested Resources

query searchEquipmentByName($nameLike: String!){
  equipment(nameLike: $nameLike) {
    id  
    name
    quantity
    resource_folder {
      name
      ancestors {
        name
      }
    }
  }
}

Event Comments

Event Comments

query getEventPosts(
    $eventId: Int!
    $eventPostKind: EventPostKinds
    $eventPostBodyContains: String
    $eventPostOffset: Int
    $eventPostLimit: Int
  ) {
  event(id: $eventId) {
    event_posts(kind: $eventPostKind, contains: $eventPostBodyContains, offset: $eventPostOffset, limit: $eventPostLimit) {
      id
      kind
      created_at {
        date: strftime(format: "%B %d, %Y")
        time
      }
      created_by {
        id
        name
        thumbnail_url
      }
      ... EventPostUpdateFields
    }
  }
}

Event Comments

mutation EventPostUpdate($id: Int!, $params: EventPostParams!) {
  update_event_post(id: $id, params: $params) {
    ...EventPostUpdateFields
  }
}
fragment EventPostUpdateFields on EventPost {
  body
  edited_at {
    date: strftime(format: "%B %d, %Y")
    time
  }
}

Recurrence Preview

Recurrence Preview

query previewEventTemplates(
    $eventTemplates: [EventTemplateInput]!
    $previewStartsAt: String!
    $previewEndsAt: String!
  ) {
  event_template_previews(event_templates: $eventTemplates) {
    description
    errors
    instance_previews(starts_at: $previewStartsAt, ends_at: $previewEndsAt) {
      starts_at { formatted: strftime(format: "%FT%T") }
      ends_at   { formatted: strftime(format: "%FT%T") }
    }
  }
}
field :event_template_previews, types[EventTemplateType] do 
  description "Generate a preview based on event template selections"
  argument :event_templates, !types[EventTemplateInputType]
  resolve -> (obj, args, ctx) {
    args[:event_templates].map { |et_args| EventTemplate.new(et_args) }
  }
end

New in GraphQL

  • Rewritten Lexer & Parser
  • Query "Complexity" Limit 
  • Analysis Phase 
  • Dynamic Schema Masking
  • Zero-Overhead Instrumentation

Future in GraphQL

  • Schema Maintenance Helpers
  • Generic Promise/Future Support 
  • Codegen (Immutable.Record, plz)
  • Rails-driven client (persisted queries)
  • @defer / @stream

The End

Questions?

http://rmosolgo.github.io/graphql-ruby/

Made with Slides.com