Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
Created January 3, 2025 14:40
Show Gist options
  • Save rmosolgo/d055571ebdc252be7c6b3badd0cd5c80 to your computer and use it in GitHub Desktop.
Save rmosolgo/d055571ebdc252be7c6b3badd0cd5c80 to your computer and use it in GitHub Desktop.
Make Edge.node non-null in GraphQL-Ruby
require "bundler/inline"
gemfile do
gem "graphql", "2.4.7"
end
class MySchema < GraphQL::Schema
class BaseEdge < GraphQL::Types::Relay::BaseEdge
node_nullable(false)
end
class BaseConnection < GraphQL::Types::Relay::BaseConnection
edge_nullable(false)
edges_nullable(false)
node_nullable(false)
end
class Item < GraphQL::Schema::Object
edge_type_class(BaseEdge)
connection_type_class(BaseConnection)
end
class Query < GraphQL::Schema::Object
field :items, Item.connection_type
end
query(Query)
end
puts MySchema.to_definition
# """
# The connection type for Item.
# """
# type ItemConnection {
# """
# A list of edges.
# """
# edges: [ItemEdge!]!
# """
# A list of nodes.
# """
# nodes: [Item!]!
# """
# Information to aid in pagination.
# """
# pageInfo: PageInfo!
# }
# """
# An edge in a connection.
# """
# type ItemEdge {
# """
# A cursor for use in pagination.
# """
# cursor: String!
# """
# The item at the end of the edge.
# """
# node: Item!
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment