ObjectToGraphQL
GraphQL Query generator from Ruby object structure.
gem 'object_to_graphql'
Usage
object = {
user: {
name: "Alice",
email_address: "alice@example.com",
accounts: [
{ name: "alice1" },
],
}
}
ObjectToGraphQL.generate(object)
It works with arguments
object = {
user: {
name: "Alice",
email_address: "alice@example.com",
accounts: [
{ name: "alice1" },
],
}
}
arguments = [
[[:user], {name: "ID", value: "id-1"}]
[[:user, :name], {name: "separator", value: ","}],
[[:user, :accounts], {name: "order", value: "desc"}]
]
ObjectToGraphQL.generate(object, arguments)
It works with variables
object = {
user: {
name: "Alice",
email_address: "alice@example.com",
accounts: [
{ name: "alice1" },
],
}
}
arguments = [
[[:user], {name: "id", value: "$user_id"}],
]
variables = [
{name: "$user_id", type: "ID!"}
]
ObjectToGraphQL.generate(object, arguments, variables)
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/meganemura/object_to_graphql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the ObjectToGraphQL project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.