Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GraphQL

Vinícius Palma
December 06, 2017
43

 GraphQL

Vinícius Palma

December 06, 2017
Tweet

Transcript

  1. Expectation GraphQL in popular languages - 2 years Startups -

    1 years Tech giants - 4 years Personal projects - 2~6 mouths
  2. Reality GraphQL in popular languages - 4 ~ 6 mouths

    Startups - 6 ~ 12 mouths Tech giants - 2 years Personal projects - 1 ~ 2 mouths
  3. Types ::StatsEvidenceType = GraphQL ::ObjectType.define do name 'Stats Evidence' field

    :status, types.String field :attribute, types.String field :actual, types.Float field :previous, types.Float end
  4. Types ::ChampionType = GraphQL ::ObjectType.define do name “Champion" field :id,

    !types.ID field :version, types.String field :api_id, types.String … field :stats, -> { Types ::StatsType } field :image, -> { Types ::ImageType } field :skins, -> { Types ::SkinType.to_list_type } field :change, Types ::ChangeType do resolve -> (champion, _, _) { Resolvers ::ChangesResolver.(champion: champion) } end end
  5. Types ::QueryType = GraphQL ::ObjectType.define do name "Query" field :champion

    do description "Query to find a champion by your id and version number" type Types ::ChampionType argument :name, !types.String argument :version, !types.String resolve ->(_, args, _) { Champion.find_by(name: args[:name].titlecase, version: args[:version]) } end end
  6. MutationType = GraphQL ::ObjectType.define do name "Mutation" field :addPost, PostType

    do description "Adds a Post." argument :post, PostInputType resolve -> (_, args, _) { Post.create!(args[:post]) } end end
  7. { “data”: { “me”: { “firstName”: “Elliot”, “lastName”: “Alderson”, …

    “friends”: [ { “name”: “Mr. Robot” }, { “name”: “Tyrell” } ] } } }
  8. // Mutation mutation CreateReviewForEpisode($ep: “JEDI”, $review: ReviewInput!) { createReview(episode: $ep,

    review: $review) { stars commentary } } // Variables { "ep": "JEDI", "review": { "stars": 5, "commentary": "This is a great movie!" } }