Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

salesforce-graphql

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

salesforce-graphql

### Installation

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

salesforce graphql
Build Status Coverage Status

salesforce-graphql - Bringing the GraphQL query language to Salesforce

Getting Started

Installation

$ yarn add salesforce-graphql jsforce

Example

app.ts
import * as jsforce from 'jsforce';
import * as path from 'path';
import * as fs from 'fs';

import { GraphQLServer } from 'graphql-yoga';
import { Binding } from 'salesforce-graphql';

const schemaFile = path.join(__dirname, 'schema.graphql');
const typeDefs = fs.readFileSync(schemaFile, 'utf8');

const { USERNAME, PASSWORD } = process.env;

const resolvers = {
  Query: {
    Accounts: (parent, args, context, info) =>
      context.db.query({}, info).then(res => res.records),
    Account: (parent, args, context, info) =>
      context.db.query({}, info).then(res => res.records[0]),
    Contacts: (parent, args, context, info) =>
      context.db.query({}, info).then(res => res.records),
    Contact: (parentobj, args, context, info) =>
      context.db.query({}, info).then(res => res.records[0]),
  },
  Account: {
    Contacts: (parent, args, context, info) =>
      context.db.query({ AccountId: parent.Id }, info).then(res => res.records),
  },
  Contact: {
    Account: (parent, args, context, info) =>
      context.db.query({ Id: parent.AccountId }, info).then(res => res.records[0]),
  },
};

const conn = new jsforce.Connection({});

function init() {
  const db = new Binding({ conn });

  const server = new GraphQLServer({
    typeDefs,
    resolvers,
    context: req => ({ ...req, db }),
  });

  server.start({ playground: '/playground' }, ({ port }) =>
    console.log('Server is running on localhost:' + port)
  );
}

conn.login(USERNAME, PASSWORD, (err, userinfo) => init());
schema.graphql
type Query {
  Account(Id: ID!): Account
  Accounts(limit: Int): [Account]
  Contact(Id: ID!): Contact
  Contacts(limit: Int): [Contact]
}

type Account {
  Id: ID!
  IsDeleted: Boolean
  Name: String
  Type: String

  Contacts(limit: Int): [Contact]
}

type Contact {
  Id: ID!
  Account: Account
  AccountId: String
  LastName: String
  FirstName: String
  Salutation: String
  Name: String
}

When you are ready, start the GraphQL server:

$ yarn start

Head over to http://localhost:4000/playground to test with the following query:

{
  Account(Id: "001E000001KnMkTIAV") {
    Id
    Name
    Contacts(limit: 1) {
      Name
      AccountId
      Account {
        Name
      }
    }
  }
}

Sample Output

TODO

  • Subscriptions
  • Mutations
  • Basically everything

References

Extra

FAQs

Package last updated on 18 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc