Skip to content

Commit

Permalink
feat: Add constant info to graphql schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 15, 2020
1 parent a96cb28 commit b6d7198
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions plugins/gatsby-source-newrelic-sdk/src/constantInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const IGNORED_PROPERTIES = [
'prototype',
'length',
'name',
'propTypes',
'getDerivedStateFromProps',
'defaultProps',
];

exports.getConstants = (name, sdk) => {
const obj = sdk[name];

return Object.getOwnPropertyNames(obj)
.filter(
(member) =>
!IGNORED_PROPERTIES.includes(member) &&
typeof obj[member] !== 'function'
)
.map((member) => {
const value = obj[member];

return {
name: `${name}.${member}`,
type: Array.isArray(value) ? 'array' : typeof value,
values: Array.isArray(value)
? value.map((el) => JSON.stringify(el))
: Object.getOwnPropertyNames(value).map(
(key) => `${key}: ${JSON.stringify(value[key])}`
),
};
});
};
3 changes: 3 additions & 0 deletions plugins/gatsby-source-newrelic-sdk/src/docInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { getExamples } = require('./exampleInfo');
const { getTypeDefs } = require('./typeDefInfo');
const { getPropTypes } = require('./propTypeInfo');
const { getMethods } = require('./methodInfo');
const { getConstants } = require('./constantInfo');

exports.getComponentDoc = (name, sdk) => {
const component = sdk[name];
Expand All @@ -21,6 +22,7 @@ exports.getComponentDoc = (name, sdk) => {
return {
name,
usage: `import { ${name} } from 'nr1'`,
constants: getConstants(name, sdk),
description: component.__docs__.text,
examples: getExamples(name, sdk),
propTypes: getPropTypes(component),
Expand All @@ -41,6 +43,7 @@ exports.getApiDoc = (name, sdk) => {
return {
name,
usage: `import { ${name} } from 'nr1'`,
constants: getConstants(name, sdk),
description: api.__docs__.text,
examples: getExamples(name, sdk),
methods: getMethods(name, sdk),
Expand Down

0 comments on commit b6d7198

Please sign in to comment.