Skip to content
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

feat(CodeBlock): Pass variables into graphqlPlayground url #362

Merged
merged 5 commits into from
Dec 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export const CodeBlock = ({

const child = children[index];

const rawVariables =
const jsoncVariables =
children[0].language === 'graphql' && children[1]?.label === 'Variables'
? children[1].code
: undefined;

const variables = JSON.stringify(parse(rawVariables ?? '{}'), null, 2);
const variables = JSON.stringify(parse(jsoncVariables ?? '{}'), null, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this to avoid parsing/stringifying empty objects for other code block types:

Suggested change
const variables = JSON.stringify(parse(jsoncVariables ?? '{}'), null, 2);
const variables = jsoncVariables && JSON.stringify(parse(jsoncVariables), null, 2);


const graphqlPlaygroundButton =
children[0].language === 'graphql' && graphqlPlayground ? (
Expand Down