mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
24 lines
690 B
TypeScript
24 lines
690 B
TypeScript
import { astFromValue, print } from 'graphql';
|
|
import React, { FC, memo } from 'react';
|
|
|
|
import { GraphQLFieldWithParentName } from './graph-ql-types';
|
|
|
|
interface Props {
|
|
field: GraphQLFieldWithParentName;
|
|
}
|
|
|
|
export const GraphQLDefaultValue: FC<Props> = memo(({ field }) => {
|
|
// Make Flow happy :/
|
|
const fieldO: Record<string, any> = field;
|
|
|
|
if ('defaultValue' in fieldO && fieldO.defaultValue !== undefined) {
|
|
const ast = astFromValue(fieldO.defaultValue, fieldO.type);
|
|
const strDefault = ast ? print(ast) : '';
|
|
return <span className="success">{` = ${strDefault}`}</span>;
|
|
} else {
|
|
return null;
|
|
}
|
|
});
|
|
|
|
GraphQLDefaultValue.displayName = 'GraphQLDefaultValue';
|