Skip to content

Commit

Permalink
Add Country type
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianRimondi committed Jul 12, 2019
1 parent bd8849a commit df08d37
Show file tree
Hide file tree
Showing 4 changed files with 696 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/spree/graphql/types/country.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Spree
module Graphql
module Types
class Country < Base::RelayNode
field :iso_name, String, null: false
field :iso, String, null: false
field :iso3, String, null: false
field :name, String, null: false
field :numcode, Integer, null: false
field :states_required, Boolean, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
end
end
end
end
5 changes: 5 additions & 0 deletions lib/spree/graphql/types/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class Query < Types::Base::Object

# Fetches a list of objects given a list of UUIDs
field :nodes, field: GraphQL::Relay::Node.plural_field

field :countries, Types::Country.connection_type, null: false, description: "Supported Countries"
def countries
Spree::Country.all
end
end
end
end
Expand Down
131 changes: 131 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,2 +1,133 @@
type Country implements Node {
createdAt: ISO8601DateTime
id: ID!
iso: String!
iso3: String!
isoName: String!
name: String!
numcode: Int!
statesRequired: Boolean!
updatedAt: ISO8601DateTime
}

"""
The connection type for Country.
"""
type CountryConnection {
"""
A list of edges.
"""
edges: [CountryEdge]

"""
A list of nodes.
"""
nodes: [Country]

"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}

"""
An edge in a connection.
"""
type CountryEdge {
"""
A cursor for use in pagination.
"""
cursor: String!

"""
The item at the end of the edge.
"""
node: Country
}

"""
An ISO 8601-encoded datetime
"""
scalar ISO8601DateTime

"""
An object with an ID.
"""
interface Node {
"""
ID of the object.
"""
id: ID!
}

"""
Information about pagination in a connection.
"""
type PageInfo {
"""
When paginating forwards, the cursor to continue.
"""
endCursor: String

"""
When paginating forwards, are there more items?
"""
hasNextPage: Boolean!

"""
When paginating backwards, are there more items?
"""
hasPreviousPage: Boolean!

"""
When paginating backwards, the cursor to continue.
"""
startCursor: String
}

type Query {
"""
Supported Countries
"""
countries(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Returns the elements in the list that come before the specified cursor.
"""
before: String

"""
Returns the first _n_ elements from the list.
"""
first: Int

"""
Returns the last _n_ elements from the list.
"""
last: Int
): CountryConnection!

"""
Fetches an object given its ID.
"""
node(
"""
ID of the object.
"""
id: ID!
): Node

"""
Fetches a list of objects given a list of IDs.
"""
nodes(
"""
IDs of the objects.
"""
ids: [ID!]!
): [Node]!
}

0 comments on commit df08d37

Please sign in to comment.