Skip to content

Latest commit

 

History

History
69 lines (49 loc) · 1.29 KB

client.md

File metadata and controls

69 lines (49 loc) · 1.29 KB

Client

Initialization

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: '...')

query and mutation actions

mutation = client.mutation(:create_user)
query = client.query(:find_user)

where (alias: input)

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" }) {
    ...
  }
}

select (alias: output)

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 }
  }
}

meta

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" }