{"id":13416477,"url":"https://github.com/tb/northwind-graphql-ruby","last_synced_at":"2025-07-16T01:19:05.387Z","repository":{"id":137883783,"uuid":"105811840","full_name":"tb/northwind-graphql-ruby","owner":"tb","description":"Northwind graphql-ruby","archived":false,"fork":false,"pushed_at":"2019-02-03T10:33:18.000Z","size":380,"stargazers_count":24,"open_issues_count":7,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T01:37:24.267Z","etag":null,"topics":["api","demo-app","graphql","rails","workshops"],"latest_commit_sha":null,"homepage":"http://northwind-graphql-ruby.herokuapp.com/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-04T19:54:04.000Z","updated_at":"2022-03-29T22:49:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"893cbdbc-c4f1-4d94-8397-62ffc000dcc2","html_url":"https://github.com/tb/northwind-graphql-ruby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tb/northwind-graphql-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tb%2Fnorthwind-graphql-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tb%2Fnorthwind-graphql-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tb%2Fnorthwind-graphql-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tb%2Fnorthwind-graphql-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tb","download_url":"https://codeload.github.com/tb/northwind-graphql-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tb%2Fnorthwind-graphql-ruby/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265473264,"owners_count":23772083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","demo-app","graphql","rails","workshops"],"created_at":"2024-07-30T21:00:59.368Z","updated_at":"2025-07-16T01:19:05.341Z","avatar_url":"https://github.com/tb.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# northwind-graphql-ruby\n\nby [GraphQL Developers @ Selleo](https://selleo.com/graphql-expert-developers-team)\n\n[![Build Status](https://travis-ci.org/tb/northwind-graphql-ruby.svg?branch=master)](https://travis-ci.org/tb/northwind-graphql-ruby)\n\n## [Demo](http://northwind-graphql-ruby.herokuapp.com)\n\n![GitHub Logo](http://g.recordit.co/YLXJDYKPZn.gif)\n\n## Initial project setup\n\n    gem install rails\n    rails new northwind-graphql-ruby --api --database=postgresql\n    echo northwind-graphql-ruby \u003e northwind-graphql-ruby/.ruby-gemset\n    echo 2.4.2 \u003e northwind-graphql-ruby/.ruby-version\n    cd northwind-graphql-ruby\n    gem install bundler\n\n## Setup data \n\n    rake db:setup\n\nSee [Entity-Relationship Diagrams PDF](erd.pdf)\n\n## Setup GraphQL\n\nAdd to Gemfile\n\n    gem 'graphql'\n    gem 'batch-loader'\n\n    group :development do\n      # ...\n      # graphiql in development https://github.com/rmosolgo/graphiql-rails/issues/13#issuecomment-256256255\n      gem 'sass-rails'\n      gem 'uglifier'\n      gem 'coffee-rails'\n      gem 'graphiql-rails'\n    end\n\nThen run\n\n    bundle\n    rails generate graphql:install\n\nAdd the engine to `routes.rb`\n\n    Rails.application.routes.draw do\n      post \"/graphql\", to: \"graphql#execute\"\n      if Rails.env.development?\n        mount GraphiQL::Rails::Engine, at: \"/graphiql\", graphql_path: \"/graphql\"\n      end\n    end\n\nAnd start server\n\n    rails s\n    open http://localhost:3000/graphiql\n\nQuery GraphQL API\n\n    query { testField }\n\nRead [Introduction to GraphQL](http://graphql.org/learn/)\n\n## Types\n\nGraphQL queries begin from [root types](http://graphql-ruby.org/schema/root_types.html): query, mutation, and subscription (experimental).\n\n[Types](http://graphql-ruby.org/types/introduction.html) describe objects and values in a system.\n\nTo query and mutate models we will define two types for each model\n\n    Types::SupplierType = GraphQL::ObjectType.define do\n      name \"Supplier\"\n\n      field :id, !types.ID\n      field :name, types.String\n      field :webpage, types.String\n      field :notes, types.String\n      field :errors, Types::JSONType\n    end\n\n    Types::SupplierInputType = GraphQL::InputObjectType.define do\n      name \"SupplierInput\"\n\n      argument :id, types.ID\n      argument :name, types.String\n      argument :webpage, types.String\n      argument :notes, types.String\n    end\n\nand some custom types with `GraphQL::ScalarTypes` like\n\n    Types::DateType = GraphQL::ScalarType.define do\n      name \"Date\"\n\n      coerce_input -\u003e(value, ctx) { Date.iso8601(value) }\n      coerce_result -\u003e(value, ctx) { value.iso8601 }\n    end\n\n## Queries\n\nTo keep schema definition clean use [`GraphQL::Function`](http://graphql-ruby.org/fields/function.html)\n\n    Types::QueryType = GraphQL::ObjectType.define do\n      name \"Query\"\n\n      field :supplier, function: Functions::FindById.new(Supplier)\n      field :allSuppliers, function: Functions::FindAll.new(Supplier) do\n        argument :filter, Types::SupplierFilterType\n      end\n    end\n\nAbove defines queries\n\n    fragment supplierFields on Supplier {\n      id\n      name\n    }\n\n    {\n      supplier(id: 1) {\n        ...supplierFields\n      }\n      allSuppliers(offset: 1) {\n        ...supplierFields\n      }\n    }\n\n## Mutations\n\nFor mutations also use [`GraphQL::Function`](http://graphql-ruby.org/fields/function.html)\n\n    Types::MutationType = GraphQL::ObjectType.define do\n      name \"Mutation\"\n\n      field :createSupplier, function: Functions::Create.new(Supplier) do\n        argument :supplier, !Types::SupplierInputType\n      end\n      field :updateSupplier, function: Functions::Update.new(Supplier) do\n        argument :supplier, !Types::SupplierInputType\n      end\n      field :deleteSupplier, function: Functions::Delete.new(Supplier)\n    end\n\nTry mutations (run one mutation at a time)\n\n    fragment supplierFields on Supplier {\n      id\n      name\n    }\n\n    mutation {\n      createSupplier(supplier: {name: \"ACME\"}) {\n        ...supplierFields\n        errors\n      }\n    }\n\n    mutation {\n      updateSupplier(supplier: {id: 11, name: \"NewCo\"}) {\n        ...supplierFields\n        errors\n      }\n    }\n\n    mutation {\n      deleteSupplier(id: 11) {\n        ...supplierFields\n      }\n    }\n\nWe are using `Types::JSONType` to get validation `errors`, read more on [Error Handling](http://graphql-ruby.org/queries/error_handling.html)\n\n## Relations\n\nFor one-to-one relations use `Functions::HasOne` that is wrapper around [exAspArk/batch-loader](https://github.com/exAspArk/batch-loader),\n\"Powerful tool to avoid N+1 DB or HTTP queries\".\n\nFor one-to-many relations you can reuse `Functions::FindAll`.\n\n    Types::SupplierType = GraphQL::ObjectType.define do\n      name \"Supplier\"\n      #...\n\n      field :contact, function: Functions::HasOne.new('id', 'contactable_id', -\u003e (ids, obj, args, ctx) {\n        Contact.where(contactable_id: ids, contactable_type: 'Supplier')\n      }) do\n        type Types::ContactType\n      end\n      field :products, function: Functions::FindAll.new(Product, -\u003e (obj, args, ctx) {\n        obj.products\n      }) do\n        type types[Types::ProductType]\n        argument :filter, Types::ProductFilterType\n      end\n    end\n\n## Server-side REST wrapper\n\nYou can use [`GraphQL::Function`](http://graphql-ruby.org/fields/function.html)\nto write a [server-side REST wrapper](http://graphql.org/blog/rest-api-graphql-wrapper/).\nHere is example for [Fixer.io](http://fixer.io/) \"Foreign exchange rates and currency conversion API\"\n\n    class Functions::CurrencyRates \u003c GraphQL::Function\n      attr_reader :type\n    \n      def initialize\n        @type = GraphQL::ObjectType.define do\n          name \"CurrencyRates\"\n    \n          field :base, types.String\n          field :date, Types::DateType, resolve: -\u003e(obj, args, ctx) { Date.iso8601(obj['date']) }\n          field :rates, Types::JSONType\n        end\n      end\n    \n      argument :date, Types::DateType\n      argument :base, types.String, default_value: 'EUR'\n    \n      def call(obj, args, ctx)\n        params = \"#{args['date']||'latest'}?base=#{args['base']}\"\n        response = HTTParty.get(\"http://api.fixer.io/#{params}\", timeout: 10)\n        OpenStruct.new(response.parsed_response)\n      end\n    end\n\nQuery\n\n    {\n      currencyRates(date: \"2017-10-02\", base: \"EUR\") {\n        date\n        base\n        rates\n      }\n    }\n    \n## Tracking Schema with GraphQL IDL Schema Dump\n\nTo update GraphQL IDL Schema dump with rake task:\n\n    rake graphql:schema\n\nSee [Tracking Schema Changes With GraphQL-Ruby](http://rmosolgo.github.io/blog/2017/03/16/tracking-schema-changes-with-graphql-ruby/)\n\n## TODO\n\n- authorization\n- testing\n- file upload\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftb%2Fnorthwind-graphql-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftb%2Fnorthwind-graphql-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftb%2Fnorthwind-graphql-ruby/lists"}