Skip to content

Instantly share code, notes, and snippets.

@dolcalmi
Last active August 18, 2022 04:17
Show Gist options
  • Save dolcalmi/42f1622f797b1734e356315c517084d5 to your computer and use it in GitHub Desktop.
Save dolcalmi/42f1622f797b1734e356315c517084d5 to your computer and use it in GitHub Desktop.
How to test custom fields

How to test:

Validate custom fields empty schema

If customFields config is empty all related mutations and queries should not be visible by api clients.

You can validate this running make start-main (no changes to schema files)

Add custom schema to default.yaml (example)

accounts:
  initialStatus: active
  customFields:
    - name: "nationalId"
      type: "integer"
      defaultValue: 0
    - name: "firstName"
      type: "string"
      required: true
      editable: true
    - name: "lastName"
      type: "string"
      editable: true
    - name: "isPEP"
      type: "boolean"
      editable: true
      defaultValue: false
    - name: "preferences"
      type: "boolean"
      array: true
      editable: true

Update values as an user

In the main server (make start-main) run the next:

mutation AccountCustomFieldsUpdate($input: AccountCustomFieldsUpdateInput!) {
  accountCustomFieldsUpdate(input: $input) {
    errors {
      message
    }
    accountCustomFields {
      firstName
      lastName
      isPEP
      preferences
    }
  }
}

Input

{"input": {  "firstName": "Juan", "lastName": "Lopez", "isPEP": true, "preferences": [true, false, true] }}

Note: please notice that nationalId can only be updated as an editor (admin api)

Query values as an user

query me {
  me {
    defaultAccount {
      defaultWalletId
      wallets {
        id
        walletCurrency
      }
      customFields {
        firstName
        lastName
        isPEP
        preferences
      }
    }
  }
}

Note: please notice that nationalId is only visible as an editor (admin api)

Update values as an editor

In the admin server (make start-admin) as an editor run the next:

mutation AccountCustomFieldsUpdate($input: AccountCustomFieldsUpdateInput!) {
  accountCustomFieldsUpdate(input: $input) {
    errors {
      message
    }
    accountCustomFields {
      nationalId
      firstName
      lastName
      isPEP
      preferences
    }
  }
}

Input

{"input": {  "accountId": "<accountId from db>", "nationalId": 123456, "firstName": "Juan", "lastName": "Lopez", "isPEP": true, "preferences": [true, false, true] }}

Query values as an editor

query getAccountDetailsByUserPhone($phone: Phone!) {
  accountDetails: accountDetailsByUserPhone(phone: $phone) {
    id
    customFields {
      nationalId
      firstName
      lastName
      isPEP
      preferences
    }
    createdAt
  }
}

Input (updated user's phone)

{"phone": "+16505554322"}
query getAccountDetailsByUsername($username: Username!) {
  accountDetails: accountDetailsByUsername(username: $username) {
    id
    customFields { 
      nationalId
      firstName
      lastName
      isPEP
      preferences
    }
    createdAt
  }
}

Input (updated user's username)

{"username": "userB"}

Search accounts by custom field as an editor

query AccountsDetailsByCustomField($field: CustomField, $value: String!) {
  accountsDetails: accountsDetailsByCustomField(field: $field, value: $value) {
    id
    username
    customFields { 
      nationalId
      firstName
      lastName
      isPEP
      preferences
    }
    createdAt
  }
}

Input

{ "field": "nationalId", "value": "123"}
or
{ "field": "firstName", "value": "jua"}

Note: field is validated similar to the price query, only valid field names are valid values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment