Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Optional Parameters on GraphQL Query #30

Open
jmarbutt opened this issue Sep 14, 2022 · 0 comments
Open

Optional Parameters on GraphQL Query #30

jmarbutt opened this issue Sep 14, 2022 · 0 comments

Comments

@jmarbutt
Copy link

When a GraphQL Schema allows optional parameters, create them as optional parameters in the generated function.

For example with the GraphQL Schema that is at the bottom of this issue, you can do queries like this:

{
  contacts {
    id
    first_name
    last_name
  }
}

Which would be nice to translate to the generated functions like this:

var allContacts = context.Contacts();

And allowing for the optional parameters like:

var allContacts = context.Contacts(limit:100, offset: 0);

I am using hasura as a graphql server and this is the generated schema having 1 table called contacts, its a lot but thought I would share it

schema {
  query: query_root
  mutation: mutation_root
  subscription: subscription_root
}

"""whether this query should be cached (Hasura Cloud only)"""
directive @cached(
  """measured in seconds"""
  ttl: Int! = 60

  """refresh the cache entry"""
  refresh: Boolean! = false
) on QUERY

"""
Boolean expression to compare columns of type "String". All fields are combined with logical 'AND'.
"""
input String_comparison_exp {
  _eq: String
  _gt: String
  _gte: String

  """does the column match the given case-insensitive pattern"""
  _ilike: String
  _in: [String!]

  """
  does the column match the given POSIX regular expression, case insensitive
  """
  _iregex: String
  _is_null: Boolean

  """does the column match the given pattern"""
  _like: String
  _lt: String
  _lte: String
  _neq: String

  """does the column NOT match the given case-insensitive pattern"""
  _nilike: String
  _nin: [String!]

  """
  does the column NOT match the given POSIX regular expression, case insensitive
  """
  _niregex: String

  """does the column NOT match the given pattern"""
  _nlike: String

  """
  does the column NOT match the given POSIX regular expression, case sensitive
  """
  _nregex: String

  """does the column NOT match the given SQL regular expression"""
  _nsimilar: String

  """
  does the column match the given POSIX regular expression, case sensitive
  """
  _regex: String

  """does the column match the given SQL regular expression"""
  _similar: String
}

"""
columns and relationships of "contacts"
"""
type contacts {
  created_at: timestamptz!
  first_name: String!
  id: uuid!
  last_name: String!
  updated_at: timestamptz!
}

"""
aggregated selection of "contacts"
"""
type contacts_aggregate {
  aggregate: contacts_aggregate_fields
  nodes: [contacts!]!
}

"""
aggregate fields of "contacts"
"""
type contacts_aggregate_fields {
  count(columns: [contacts_select_column!], distinct: Boolean): Int!
  max: contacts_max_fields
  min: contacts_min_fields
}

"""
Boolean expression to filter rows from the table "contacts". All fields are combined with a logical 'AND'.
"""
input contacts_bool_exp {
  _and: [contacts_bool_exp!]
  _not: contacts_bool_exp
  _or: [contacts_bool_exp!]
  created_at: timestamptz_comparison_exp
  first_name: String_comparison_exp
  id: uuid_comparison_exp
  last_name: String_comparison_exp
  updated_at: timestamptz_comparison_exp
}

"""
unique or primary key constraints on table "contacts"
"""
enum contacts_constraint {
  """
  unique or primary key constraint on columns "id"
  """
  contacts_pkey
}

"""
input type for inserting data into table "contacts"
"""
input contacts_insert_input {
  created_at: timestamptz
  first_name: String
  id: uuid
  last_name: String
  updated_at: timestamptz
}

"""aggregate max on columns"""
type contacts_max_fields {
  created_at: timestamptz
  first_name: String
  id: uuid
  last_name: String
  updated_at: timestamptz
}

"""aggregate min on columns"""
type contacts_min_fields {
  created_at: timestamptz
  first_name: String
  id: uuid
  last_name: String
  updated_at: timestamptz
}

"""
response of any mutation on the table "contacts"
"""
type contacts_mutation_response {
  """number of rows affected by the mutation"""
  affected_rows: Int!

  """data from the rows affected by the mutation"""
  returning: [contacts!]!
}

"""
on_conflict condition type for table "contacts"
"""
input contacts_on_conflict {
  constraint: contacts_constraint!
  update_columns: [contacts_update_column!]! = []
  where: contacts_bool_exp
}

"""Ordering options when selecting data from "contacts"."""
input contacts_order_by {
  created_at: order_by
  first_name: order_by
  id: order_by
  last_name: order_by
  updated_at: order_by
}

"""primary key columns input for table: contacts"""
input contacts_pk_columns_input {
  id: uuid!
}

"""
select columns of table "contacts"
"""
enum contacts_select_column {
  """column name"""
  created_at

  """column name"""
  first_name

  """column name"""
  id

  """column name"""
  last_name

  """column name"""
  updated_at
}

"""
input type for updating data in table "contacts"
"""
input contacts_set_input {
  created_at: timestamptz
  first_name: String
  id: uuid
  last_name: String
  updated_at: timestamptz
}

"""
Streaming cursor of the table "contacts"
"""
input contacts_stream_cursor_input {
  """Stream column input with initial value"""
  initial_value: contacts_stream_cursor_value_input!

  """cursor ordering"""
  ordering: cursor_ordering
}

"""Initial value of the column from where the streaming should start"""
input contacts_stream_cursor_value_input {
  created_at: timestamptz
  first_name: String
  id: uuid
  last_name: String
  updated_at: timestamptz
}

"""
update columns of table "contacts"
"""
enum contacts_update_column {
  """column name"""
  created_at

  """column name"""
  first_name

  """column name"""
  id

  """column name"""
  last_name

  """column name"""
  updated_at
}

input contacts_updates {
  """sets the columns of the filtered rows to the given values"""
  _set: contacts_set_input
  where: contacts_bool_exp!
}

"""ordering argument of a cursor"""
enum cursor_ordering {
  """ascending ordering of the cursor"""
  ASC

  """descending ordering of the cursor"""
  DESC
}

"""mutation root"""
type mutation_root {
  """
  delete data from the table: "contacts"
  """
  delete_contacts(
    """filter the rows which have to be deleted"""
    where: contacts_bool_exp!
  ): contacts_mutation_response

  """
  delete single row from the table: "contacts"
  """
  delete_contacts_by_pk(id: uuid!): contacts

  """
  insert data into the table: "contacts"
  """
  insert_contacts(
    """the rows to be inserted"""
    objects: [contacts_insert_input!]!

    """upsert condition"""
    on_conflict: contacts_on_conflict
  ): contacts_mutation_response

  """
  insert a single row into the table: "contacts"
  """
  insert_contacts_one(
    """the row to be inserted"""
    object: contacts_insert_input!

    """upsert condition"""
    on_conflict: contacts_on_conflict
  ): contacts

  """
  update data of the table: "contacts"
  """
  update_contacts(
    """sets the columns of the filtered rows to the given values"""
    _set: contacts_set_input

    """filter the rows which have to be updated"""
    where: contacts_bool_exp!
  ): contacts_mutation_response

  """
  update single row of the table: "contacts"
  """
  update_contacts_by_pk(
    """sets the columns of the filtered rows to the given values"""
    _set: contacts_set_input
    pk_columns: contacts_pk_columns_input!
  ): contacts

  """
  update multiples rows of table: "contacts"
  """
  update_contacts_many(
    """updates to execute, in order"""
    updates: [contacts_updates!]!
  ): [contacts_mutation_response]
}

"""column ordering options"""
enum order_by {
  """in ascending order, nulls last"""
  asc

  """in ascending order, nulls first"""
  asc_nulls_first

  """in ascending order, nulls last"""
  asc_nulls_last

  """in descending order, nulls first"""
  desc

  """in descending order, nulls first"""
  desc_nulls_first

  """in descending order, nulls last"""
  desc_nulls_last
}

type query_root {
  """
  fetch data from the table: "contacts"
  """
  contacts(
    """distinct select on columns"""
    distinct_on: [contacts_select_column!]

    """limit the number of rows returned"""
    limit: Int

    """skip the first n rows. Use only with order_by"""
    offset: Int

    """sort the rows by one or more columns"""
    order_by: [contacts_order_by!]

    """filter the rows returned"""
    where: contacts_bool_exp
  ): [contacts!]!

  """
  fetch aggregated fields from the table: "contacts"
  """
  contacts_aggregate(
    """distinct select on columns"""
    distinct_on: [contacts_select_column!]

    """limit the number of rows returned"""
    limit: Int

    """skip the first n rows. Use only with order_by"""
    offset: Int

    """sort the rows by one or more columns"""
    order_by: [contacts_order_by!]

    """filter the rows returned"""
    where: contacts_bool_exp
  ): contacts_aggregate!

  """fetch data from the table: "contacts" using primary key columns"""
  contacts_by_pk(id: uuid!): contacts
}

type subscription_root {
  """
  fetch data from the table: "contacts"
  """
  contacts(
    """distinct select on columns"""
    distinct_on: [contacts_select_column!]

    """limit the number of rows returned"""
    limit: Int

    """skip the first n rows. Use only with order_by"""
    offset: Int

    """sort the rows by one or more columns"""
    order_by: [contacts_order_by!]

    """filter the rows returned"""
    where: contacts_bool_exp
  ): [contacts!]!

  """
  fetch aggregated fields from the table: "contacts"
  """
  contacts_aggregate(
    """distinct select on columns"""
    distinct_on: [contacts_select_column!]

    """limit the number of rows returned"""
    limit: Int

    """skip the first n rows. Use only with order_by"""
    offset: Int

    """sort the rows by one or more columns"""
    order_by: [contacts_order_by!]

    """filter the rows returned"""
    where: contacts_bool_exp
  ): contacts_aggregate!

  """fetch data from the table: "contacts" using primary key columns"""
  contacts_by_pk(id: uuid!): contacts

  """
  fetch data from the table in a streaming manner : "contacts"
  """
  contacts_stream(
    """maximum number of rows returned in a single batch"""
    batch_size: Int!

    """cursor to stream the results returned by the query"""
    cursor: [contacts_stream_cursor_input]!

    """filter the rows returned"""
    where: contacts_bool_exp
  ): [contacts!]!
}

scalar timestamptz

"""
Boolean expression to compare columns of type "timestamptz". All fields are combined with logical 'AND'.
"""
input timestamptz_comparison_exp {
  _eq: timestamptz
  _gt: timestamptz
  _gte: timestamptz
  _in: [timestamptz!]
  _is_null: Boolean
  _lt: timestamptz
  _lte: timestamptz
  _neq: timestamptz
  _nin: [timestamptz!]
}

scalar uuid

"""
Boolean expression to compare columns of type "uuid". All fields are combined with logical 'AND'.
"""
input uuid_comparison_exp {
  _eq: uuid
  _gt: uuid
  _gte: uuid
  _in: [uuid!]
  _is_null: Boolean
  _lt: uuid
  _lte: uuid
  _neq: uuid
  _nin: [uuid!]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant