generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
W-16501195 Wr/api request graphql #6
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
10344bc
feat: add api request graphql command, UTs, NUTs
WillieRuemmele 45c20e4
test: add logging
WillieRuemmele e7060cf
refactor: move test files, local project
WillieRuemmele 29af640
chore: populate force-app
WillieRuemmele a02aaa3
chore: remove logging
WillieRuemmele d4c08e4
chore: merge with wr/orgApiRest
WillieRuemmele 91e05d1
chore: update --body flag to read file/stdin/value
WillieRuemmele 4816fdd
chore: share flags/methods
WillieRuemmele 40377aa
chore: merge with base
WillieRuemmele 33d1173
chore: fix shared method, got method
WillieRuemmele 03829eb
chore: merge main, resolve conflicts
WillieRuemmele 16460fd
Merge remote-tracking branch 'origin/main' into wr/apiRequestGraphql
mshanemc a367813
Merge branch 'wr/apiRequestGraphql' of https://github.com/salesforcec…
mshanemc cbb8441
chore: --api-version
WillieRuemmele 8e3f715
Merge branch 'wr/apiRequestGraphql' of github.com:salesforcecli/plugi…
WillieRuemmele 529d77f
chore: example/classes
WillieRuemmele e148592
chore: add .gitkeep in sample proj
WillieRuemmele 322e995
test: add NUT with --body and directly passing in grapql
WillieRuemmele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# summary | ||
|
||
Execute GraphQL statements | ||
|
||
# description | ||
|
||
Run any valid GraphQL statement via the /graphql [API](https://developer.salesforce.com/docs/platform/graphql/guide/graphql-about.html) | ||
|
||
# examples | ||
|
||
- Runs the graphql query directly via the command line | ||
|
||
<%= config.bin %> <%= command.id %> --body '{ "query": "query accounts { uiapi { query { Account { edges { node { Id \n Name { value } } } } } } }" }' | ||
|
||
- Runs a mutation to create an Account, with an `example.txt` file, containing | ||
|
||
```text | ||
mutation AccountExample{ | ||
uiapi { | ||
AccountCreate(input: { | ||
Account: { | ||
Name: "Trailblazer Express" | ||
} | ||
}) { | ||
Record { | ||
Id | ||
Name { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
<%= config.bin %> <%= command.id %> --body example.txt | ||
|
||
will create a new account returning specified fields (Id, Name) | ||
|
||
# flags.header.summary | ||
|
||
HTTP header in "key:value" format. | ||
|
||
# flags.body.summary | ||
|
||
File or content with GraphQL statement. Specify "-" to read from standard input. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# flags.include.summary | ||
|
||
Include the HTTP response status and headers in the output. | ||
|
||
# flags.stream-to-file.summary | ||
|
||
Stream responses to a file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import fs from 'node:fs'; | ||
import * as os from 'node:os'; | ||
import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; | ||
import { Messages, Org, SFDX_HTTP_HEADERS } from '@salesforce/core'; | ||
import { ProxyAgent } from 'proxy-agent'; | ||
import { includeFlag, sendAndPrintRequest, streamToFileFlag } from '../../../shared/shared.js'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-api', 'graphql'); | ||
|
||
export default class Graphql extends SfCommand<void> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
public static readonly state = 'beta'; | ||
|
||
public static readonly flags = { | ||
'target-org': Flags.requiredOrg(), | ||
'stream-to-file': streamToFileFlag, | ||
include: includeFlag, | ||
body: Flags.string({ | ||
summary: messages.getMessage('flags.body.summary'), | ||
allowStdin: true, | ||
helpValue: 'file', | ||
required: true, | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const { flags } = await this.parse(Graphql); | ||
|
||
const org = flags['target-org']; | ||
const streamFile = flags['stream-to-file']; | ||
const apiVersion = await org.retrieveMaxApiVersion(); | ||
const body = `{"query":"${(fs.existsSync(flags.body) ? fs.readFileSync(flags.body, 'utf8') : flags.body) | ||
.replaceAll(os.EOL, '\\n') | ||
.replaceAll('"', '\\"')}"}`; | ||
|
||
await org.refreshAuth(); | ||
|
||
const url = new URL(`${org.getField<string>(Org.Fields.INSTANCE_URL)}/services/data/v${apiVersion}/graphql`); | ||
|
||
const options = { | ||
agent: { https: new ProxyAgent() }, | ||
headers: { | ||
...SFDX_HTTP_HEADERS, | ||
Authorization: `Bearer ${org.getConnection(apiVersion).getConnectionOptions().accessToken!}`, | ||
}, | ||
body, | ||
throwHttpErrors: false, | ||
followRedirect: false, | ||
}; | ||
|
||
await sendAndPrintRequest({ streamFile, url, options, include: flags.include, this: this }); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should do like
rest
does and allow user to set it.Imagine someone trying to repro a bug that's API dependent, etc.