Skip to content

Commit d0809b1

Browse files
committed
Added support for default values in the Config.graphqls files for the documentation
Related PR for the actual schema generation Code-Hex/graphql-codegen-typescript-validation-schema#398
1 parent a360bf9 commit d0809b1

File tree

9 files changed

+39
-10
lines changed

9 files changed

+39
-10
lines changed

.changeset/weak-carrots-check.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@graphcommerce/graphql-codegen-markdown-docs': patch
3+
'@graphcommerce/demo-magento-graphcommerce': patch
4+
'@graphcommerce/magento-compare': patch
5+
'@graphcommerce/magento-product': patch
6+
'@graphcommerce/next-config': patch
7+
'@graphcommerce/docs': patch
8+
---
9+
10+
Added support for default values in the Config.graphqls files for the documentation

docs/framework/config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ When Magento's StoreConfig adds this value, this can be replaced.
115115

116116
Use compare functionality
117117

118-
#### `compareVariant: [CompareVariant](#CompareVariant)`
118+
#### `compareVariant: [CompareVariant](#CompareVariant) (default: ICON)`
119119

120120
By default the compare feature is denoted with a 'compare ICON' (2 arrows facing one another).
121121
This may be fine for experienced users, but for more clarity it's also possible to present the compare feature as a CHECKBOX accompanied by the 'Compare' label
@@ -132,7 +132,7 @@ This value should match Magento 2's configuration value for
132132

133133
Debug configuration for GraphCommerce
134134

135-
#### `demoMode: Boolean`
135+
#### `demoMode: Boolean (default: true)`
136136

137137
Enables some demo specific code that is probably not useful for a project:
138138

@@ -214,7 +214,7 @@ Limit the static generation of SSG when building
214214

215215
To enable next.js' preview mode, configure the secret you'd like to use.
216216

217-
#### `productFiltersLayout: [ProductFiltersLayout](#ProductFiltersLayout)`
217+
#### `productFiltersLayout: [ProductFiltersLayout](#ProductFiltersLayout) (default: DEFAULT)`
218218

219219
Layout how the filters are rendered.
220220
DEFAULT: Will be rendered as horzontal chips on desktop and mobile

packages/demo-magento-graphcommerce/Config.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ extend input GraphCommerceConfig {
66
- Adds "dominant_color" attribute swatches to the product list items.
77
- Creates a big list items in the product list.
88
"""
9-
demoMode: Boolean
9+
demoMode: Boolean = true
1010
}

packages/magento-compare/Config.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ extend input GraphCommerceConfig {
1313
By default the compare feature is denoted with a 'compare ICON' (2 arrows facing one another).
1414
This may be fine for experienced users, but for more clarity it's also possible to present the compare feature as a CHECKBOX accompanied by the 'Compare' label
1515
"""
16-
compareVariant: CompareVariant
16+
compareVariant: CompareVariant = ICON
1717
}

packages/magento-product/Config.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extend input GraphCommerceConfig {
2424
DEFAULT: Will be rendered as horzontal chips on desktop and mobile
2525
SIDEBAR: Will be rendered as a sidebar on desktop and horizontal chips on mobile
2626
"""
27-
productFiltersLayout: ProductFiltersLayout
27+
productFiltersLayout: ProductFiltersLayout = DEFAULT
2828

2929
"""
3030
By default we route products to /p/[url] but you can change this to /product/[url] if you wish.

packagesDev/graphql-codegen-markdown-docs/dist/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ const plugin = (schema, _documents, config) => {
2525
leave: (node) => possibleScalars.includes(node.name) ? node.name : `[${node.name}](#${node.name})`,
2626
},
2727
StringValue: { leave: (node) => node.value },
28+
BooleanValue: { leave: (node) => node.value },
29+
EnumValue: { leave: (node) => node.value },
30+
IntValue: { leave: (node) => node.value },
31+
FloatValue: { leave: (node) => node.value },
2832
ListType: { leave: (node) => `[${node.type}]` },
2933
NonNullType: {
3034
leave: (node) => `${node.type}!`,
3135
},
3236
InputValueDefinition: {
33-
leave: (node) => `\`${node.name}: ${node.type}\`${descriptionText(node)}`,
37+
leave: (node) => {
38+
const defaultValue = node.defaultValue ? ` (default: ${node.defaultValue})` : '';
39+
return `\`${node.name}: ${node.type}${defaultValue}\`${descriptionText(node)}`;
40+
},
3441
},
3542
InputObjectTypeDefinition: {
3643
enter: (node) => ({

packagesDev/graphql-codegen-markdown-docs/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { PluginFunction, Types } from '@graphql-codegen/plugin-helpers'
2-
import { getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers'
1+
import {
2+
PluginFunction,
3+
Types,
4+
getCachedDocumentNodeFromSchema,
5+
} from '@graphql-codegen/plugin-helpers'
36
import { GraphQLSchema, visit } from 'graphql'
47
import { MarkdownDocsPluginConfig } from './config'
58

@@ -35,12 +38,19 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
3538
possibleScalars.includes(node.name) ? node.name : `[${node.name}](#${node.name})`,
3639
}, // String, Boolean, GraphCommerceDebugConfig, etc.
3740
StringValue: { leave: (node) => node.value },
41+
BooleanValue: { leave: (node) => node.value },
42+
EnumValue: { leave: (node) => node.value },
43+
IntValue: { leave: (node) => node.value },
44+
FloatValue: { leave: (node) => node.value },
3845
ListType: { leave: (node) => `[${node.type}]` },
3946
NonNullType: {
4047
leave: (node) => `${node.type}!`,
4148
},
4249
InputValueDefinition: {
43-
leave: (node) => `\`${node.name}: ${node.type}\`${descriptionText(node)}`,
50+
leave: (node) => {
51+
const defaultValue = node.defaultValue ? ` (default: ${node.defaultValue})` : ''
52+
return `\`${node.name}: ${node.type}${defaultValue}\`${descriptionText(node)}`
53+
},
4454
},
4555
InputObjectTypeDefinition: {
4656
enter: (node) => ({

packagesDev/next-config/dist/config/demoConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exports.demoConfig = {
1919
{ locale: 'en-ca', magentoStoreCode: 'en_CA' },
2020
],
2121
productFiltersPro: true,
22+
productFiltersLayout: 'DEFAULT',
2223
robotsAllow: false,
2324
demoMode: true,
2425
limitSsg: true,

packagesDev/next-config/src/config/demoConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const demoConfig: PartialDeep<GraphCommerceConfig, { recurseIntoArrays: t
2121
{ locale: 'en-ca', magentoStoreCode: 'en_CA' },
2222
],
2323
productFiltersPro: true,
24+
productFiltersLayout: 'DEFAULT',
2425
robotsAllow: false,
2526
demoMode: true,
2627
limitSsg: true,

0 commit comments

Comments
 (0)