├── .npmignore ├── README.md ├── .gitignore ├── src ├── types │ └── jsforce.d.ts ├── index.ts └── GraphQLSalesforce.ts ├── .vscode └── settings.json ├── tsconfig.json ├── package.json └── LICENSE /.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graphql-salesforce -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | node_modules 3 | -------------------------------------------------------------------------------- /src/types/jsforce.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'jsforce'; 2 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import GraphQLSalesforce from './GraphQLSalesforce'; 2 | 3 | export default GraphQLSalesforce; 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.rulers": [ 3 | 100 4 | ], 5 | "editor.tabSize": 2, 6 | "editor.wrappingColumn": 100, 7 | "files.exclude": { 8 | "lib": true, 9 | "node_modules": true 10 | }, 11 | "files.trimTrailingWhitespace": true, 12 | "typescript.tsdk": "node_modules/typescript/lib" 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "module": "commonjs", 5 | "outDir": "lib", 6 | "sourceMap": true, 7 | "strictNullChecks": true, 8 | "target": "es6" 9 | }, 10 | "files": [ 11 | "src/index.ts" 12 | ], 13 | "include": [ 14 | "src/types/*.d.ts" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graphql-salesforce", 3 | "version": "0.0.7", 4 | "description": "GraphQL for Salesforce", 5 | "keywords": [ 6 | "graphql", 7 | "salesforce" 8 | ], 9 | "homepage": "https://github.com/mjgallag/graphql-salesforce#readme", 10 | "bugs": "https://github.com/mjgallag/graphql-salesforce/issues", 11 | "license": "MIT", 12 | "author": "Michael J Gallagher ", 13 | "main": "lib/index.js", 14 | "types": "lib/index.d.ts", 15 | "repository": "mjgallag/graphql-salesforce", 16 | "scripts": { 17 | "prepublish": "rimraf lib && tsc", 18 | "watch": "tsc -w" 19 | }, 20 | "dependencies": { 21 | "jsforce": "^1.7.1" 22 | }, 23 | "devDependencies": { 24 | "@types/graphql": "^0.7.3", 25 | "rimraf": "^2.5.4", 26 | "typescript": "^2.0.10" 27 | }, 28 | "peerDependencies": { 29 | "graphql": "^0.7.2" 30 | }, 31 | "engines": { 32 | "node": ">=4" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Michael J Gallagher 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/GraphQLSalesforce.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphQLFieldConfigMap, 3 | GraphQLObjectType, 4 | GraphQLSchema, 5 | GraphQLString 6 | } from 'graphql'; 7 | import { Connection } from 'jsforce'; 8 | 9 | export default class GraphQLSalesforce { 10 | private static connection = new Connection(); 11 | 12 | static async makeSchema(username: string, password: string): Promise { 13 | const sObjectDescribePromises: Promise[] = []; 14 | 15 | await GraphQLSalesforce.connection.login(username, password); 16 | for (const sObject of (await GraphQLSalesforce.connection.describeGlobal()).sobjects) 17 | sObjectDescribePromises.push(GraphQLSalesforce.connection.sobject(sObject.name).describe()); 18 | await Promise.all(sObjectDescribePromises); 19 | 20 | return new GraphQLSchema({ 21 | query: new GraphQLObjectType({ 22 | name: 'Salesforce', 23 | fields: GraphQLSalesforce.makeObjectTypes() 24 | }) 25 | }); 26 | } 27 | 28 | private static makeObjectTypes(): GraphQLFieldConfigMap { 29 | const objectTypes: GraphQLFieldConfigMap = {}; 30 | 31 | for (const sObject of GraphQLSalesforce.connection.describeGlobal$().sobjects) 32 | objectTypes[sObject.name] = { 33 | type: new GraphQLObjectType({ 34 | name: sObject.name, 35 | fields: GraphQLSalesforce.makeScalarTypes(sObject.name) 36 | }), 37 | description: sObject.label 38 | }; 39 | 40 | return objectTypes; 41 | } 42 | 43 | private static makeScalarTypes(sObject: string): GraphQLFieldConfigMap { 44 | const scalarTypes: GraphQLFieldConfigMap = {}; 45 | 46 | for (const field of GraphQLSalesforce.connection.sobject(sObject).describe$().fields) 47 | scalarTypes[field.name] = { 48 | type: GraphQLString, 49 | description: field.label 50 | }; 51 | 52 | return scalarTypes; 53 | } 54 | } 55 | --------------------------------------------------------------------------------