All Projects → callawaycloud → apex-graphql-query

callawaycloud / apex-graphql-query

Licence: MIT license
A library for building GraphQL queries in apex

Programming Languages

Apex
172 projects

Projects that are alternatives of or similar to apex-graphql-query

universalmock
A universal mock class in Apex
Stars: ✭ 55 (+77.42%)
Mutual labels:  salesforce, apex
apex-rest-route
A simple framework for building Restful API on Salesforce
Stars: ✭ 75 (+141.94%)
Mutual labels:  salesforce, apex
codeclimate-apexmetrics
ApexMetrics - Code Climate engine for Salesforce [DISCONTINUED use CC PMD instead)
Stars: ✭ 46 (+48.39%)
Mutual labels:  salesforce, apex
Apex-Code-Conventions
Apex conventions and best practices for Salesforce Developers
Stars: ✭ 28 (-9.68%)
Mutual labels:  salesforce, apex
timeline-component-lwc
This component enables timeline view for Salesforce Record history.
Stars: ✭ 18 (-41.94%)
Mutual labels:  salesforce, apex
Sfdx Mass Action Scheduler
🚀 Declaratively schedule Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, or Apex to process records from Reports, List Views, SOQL, or Apex.
Stars: ✭ 200 (+545.16%)
Mutual labels:  salesforce, apex
apex-mocks-stress-test
Testing out FFLib versus Crud / CrudMock
Stars: ✭ 47 (+51.61%)
Mutual labels:  salesforce, apex
Apex Lambda
Functional programming for Salesforce Apex
Stars: ✭ 189 (+509.68%)
Mutual labels:  salesforce, apex
lwc-modules
Build any LWC you want without ever having to touch Apex
Stars: ✭ 20 (-35.48%)
Mutual labels:  salesforce, apex
dreaminvest-lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Financial services use case. Get inspired and learn best practices.
Stars: ✭ 41 (+32.26%)
Mutual labels:  salesforce, apex
apex-dml-mocking
DML mocking, CRUD mocking, dependency injection framework for Salesforce.com (SFDC) using Apex
Stars: ✭ 38 (+22.58%)
Mutual labels:  salesforce, apex
R.apex
Functional utility library for Apex
Stars: ✭ 80 (+158.06%)
Mutual labels:  salesforce, apex
SFDCRules
Simple yet powerful Rule Engine for Salesforce - SFDCRules
Stars: ✭ 38 (+22.58%)
Mutual labels:  salesforce, apex
Soqlx
SoqlXplorer is an awesome tool for developers using the Salesforce.com platform.
Stars: ✭ 220 (+609.68%)
Mutual labels:  salesforce, apex
Haoide
Stop upgrade, most of features were delivered in https://github.com/xjsender/haoide-vscode
Stars: ✭ 194 (+525.81%)
Mutual labels:  salesforce, apex
apex-rollup
Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
Stars: ✭ 133 (+329.03%)
Mutual labels:  salesforce, apex
Prettier Plugin Apex
Code formatter for the Apex Programming Language
Stars: ✭ 138 (+345.16%)
Mutual labels:  salesforce, apex
Dreamhouse Sfdx
Salesforce Sample App part of the sample gallery. Real estate use case. Get inspired and learn best practices.
Stars: ✭ 164 (+429.03%)
Mutual labels:  salesforce, apex
sfdc-error-playground
Lightning & Apex Error Playground
Stars: ✭ 30 (-3.23%)
Mutual labels:  salesforce, apex
ApexCallouts
A lightweight Apex library for making HTTP callouts. Works with remote site settings and named credentials.
Stars: ✭ 32 (+3.23%)
Mutual labels:  salesforce, apex

apex-graphql-query

A simple library for building GraphQL queries in Salesforce's Apex Language.

some use cases still not supported

Examples:

Query

{
  human(id: "1000") {
    name
    height
    address {
      city
      country
    }
  }
}

Equivalent Apex

GraphQLNode human = new GraphQLNode('human')
.setArguments(new GraphQLArgument('id', '1000'))
.add(new Object[]{
  'name',
  'height',
  new GraphQLNode('address')
    .add(new Object[]{ 'city', 'country' })
});

// create GraphQLQuery without Variables
GraphQLQuery qry = new GraphQLQuery(human, null);
System.debug(qry.query);

Operations

mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
  createReview(episode: $ep, review: $review) {
    stars
    commentary
  }
}
{
  "ep": "JEDI",
  "review": {
    "stars": 5,
    "commentary": "This is a great movie!"
  }
}

Equivalent Apex

//Variable DTOs
public class CreateReviewForEpisode{
  public String ep { get; set; }
  public Review review { get; set; }
}

public class Review{
  public Integer stars { get; set; }
  public String commentary { get; set; }
}

//Mutation Query
GraphQLNode node = new GraphQLNode('CreateReviewForEpisode')
.setOperation('mutation')
.addArguments(new GraphQLArgument('$ep', 'Episode!', true))
.addArguments(new GraphQLArgument('$review', 'ReviewInput!', true))
.add(
  new GraphQLNode('createReview')
  .addArguments(new GraphQLArgument[]{
    new GraphQLArgument('episode', '$ep', true),
    new GraphQLArgument('review', '$review', true)
  })
  .add(new Object[]{'stars', 'commentary'})
);

CreateReviewForEpisode createReviewVariables = new CreateReviewForEpisode();
createReviewVariables.ep = 'JEDI';
createReviewVariables.review = new Review();
createReviewVariables.review.stars = 5;
createReviewVariables.review.commentary = 'This is a great movie!';

// create GraphQLQuery with Variables
GraphQLQuery qry = new GraphQLQuery(node, createReviewVariables);
String payload = JSON.serialize(qry);

//... POST payload to graphQL service endpoint 

Additional Usage

See Unit Tests for more usage examples.

Installation

Choose your own Adventure:

A: Unlocked Package Install

OR

  • via sfdx-cli: sfdx force:package:install --wait 10 --publishwait 10 --package 04t1C000000tfGqQAI --noprompt -u you@yourorg

B: From Source

  1. sfdx force:source:convert -d deploy-package
  2. sfdx force:mdapi:deploy -d deploy-package -u you@yourorg -w 1000

Contributing

Please do!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].