to initialize graphql client, simply create new client instance with url:
client = ActiveGraphql::Client.new(url: 'http://example.com/graphql')
you can also provide extra options which will be accepted by addapter, like this:
client = ActiveGraphql::Client.new(url: 'http://example.com/graphql', headers: {}, schema_path: '...')
mutation = client.mutation(:create_user)
query = client.query(:find_user)
In order to filter values you can query with where
method:
query = query.where(name: 'John', date: { from: '2000-01-01' })
this will produce following GraphQL:
query {
find_user(name: "John", date: { from: "2000-01-01" }) {
...
}
}
In order to select which attributes you want to receive from query then you need to use select
method:
query = query.select(:name, date: [:year])
this will produce following GraphQL:
query {
find_user {
name
date { year }
}
}
You can assign meta attributes in order to use them later
query = query.meta(custom: true)
query = query.meta(also_custom: 'yes')
query.meta_attributes # => { :custom => true, :also_custom => "yes" }