for APIs • A server-side runtime for executing queries on your data ◦ In a TYPED schema YOU define • Database / Storage Engine agnostic • Implemented in many different languages
defining types • fields on those types • providing functions for each field on each type type Company { id: ID! name: String! catchPhrase: String employees: [Employee] } type Employee { id: ID! firstName: String! lastName: String! age: Int email: String company: Company }
built right in • Fetch all data for a page in one request • Flexibility for multiple different clients • No need for API versioning as you evolve the schema over time
all responses… • Caching can be an issue - needs to be keyed on the (POST) request body • Relay is clever, too clever, and not well documented - we couldn’t figure out how to use it effectively and went in favour of Apollo. Why Choose GraphQL?
framework, but pulls in Rails • Supports ActiveRecord and Sequel::Model http://graphql.pro • Authorization strategies built in • Monitoring • Persisted queries • and more...
name 'ValidationError' field :attribute, !types.String do resolve ->(obj, _arg, _ctx) { obj.first.to_s.camelize(:lower) } end field :message, !types.String do resolve ->(obj, _arg, _ctx) { obj.second.map { |elm| elm[:error] }.join(', ') } end end
{}) } let(:employee) { create(:employee) } describe 'querying for a employee and their company' do let(:query) { %`{ employee(id: #{employee.id}) { email company { name } } }` } it 'returns the employee and their company' do expect(subject.dig('data', 'employee', 'email')).to eq(employee.email) expect(subject.dig('data', 'employee', 'company', 'name')).to eq(employee.company.name) end end end
us... ◦ Lots of definition functions ◦ Lambdas passed around everywhere • Documentation wasn’t great • We wanted to experiment with Elixir ◦ Functional programming ◦ Pattern Matching ◦ Fault Tolerance ◦ etc etc… ◦ Basically, most of the things listed here: http://bit.ly/2ux5PZZ Why We Switched?
at Github and Shopify - it’s not going to go away! It helped us build a PoC GraphQL service very quickly to evaluate the approach, but we then decided to rebuild and extend with Elixir.