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

Update RAV samples to work with fetchWith create option #773

Merged
merged 59 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
bea11e3
Add --fetchWith to Vue sample
CobyPear Aug 3, 2021
0ebd6c0
Removed prerender check in if statement
CobyPear Aug 3, 2021
d8e5dd1
Use correct file extensions
CobyPear Aug 3, 2021
8a37096
Fix filename
CobyPear Aug 3, 2021
02ef91f
Update names in imports/exports
CobyPear Aug 3, 2021
080c479
Update config path
CobyPear Aug 3, 2021
52ff9aa
Refactored graphql components: vue
CobyPear Aug 4, 2021
f8a5928
Merge dev
CobyPear Aug 4, 2021
9b982b4
Extract services into factory patern - ng
CobyPear Aug 4, 2021
75d5363
Remove unused method getPlaceholderData - ng
CobyPear Aug 4, 2021
46fc7d4
Update ng graphQL components for edge schema
CobyPear Aug 4, 2021
acc1d9b
Fix lint - ng
CobyPear Aug 4, 2021
996a155
Add comment about root item ID to ng dictionary service
CobyPear Aug 4, 2021
0bb3192
Rename some variables
CobyPear Aug 4, 2021
ee052ba
Refactor react services to use factory pattern
CobyPear Aug 4, 2021
182520e
Refactor components that use an instance of the service factories
CobyPear Aug 4, 2021
7f4141e
Mend transcription errors
CobyPear Aug 4, 2021
984bbeb
Update jss-create - react
CobyPear Aug 4, 2021
2bb26db
Refactor graphql components to use edge schema - react
CobyPear Aug 4, 2021
fd4abe2
Add the call to fetchWith in jss-create - ng, react
CobyPear Aug 4, 2021
332cb89
Fix typo in variable
CobyPear Aug 4, 2021
165c03c
Fix typo
CobyPear Aug 4, 2021
635c497
Fix filepath - react
CobyPear Aug 4, 2021
d48c1d1
Import chalk to jss-create - ng
CobyPear Aug 5, 2021
bfa9a04
Update 'did you know' - ng
CobyPear Aug 5, 2021
b3a7664
Update 'did you know' - vue
CobyPear Aug 5, 2021
8e140f0
Fix filename - ng
CobyPear Aug 5, 2021
53b6d9f
Merge branch 'dev' of github.com:Sitecore/jss into feature/488863
CobyPear Aug 5, 2021
068232c
Update graphql endpoint in RAV package.json
CobyPear Aug 5, 2021
2905205
Update headless-ssr-experience-edge readme
CobyPear Aug 5, 2021
89c9ebb
Remove 'legacy' gql config - ng, react
CobyPear Aug 5, 2021
051cb60
Fix options
CobyPear Aug 5, 2021
ccff2b5
Remove querystring param from generate-config script - RAV
CobyPear Aug 5, 2021
f6ac54f
Update GraphQL Integrated Demo query - RAV
CobyPear Aug 5, 2021
d59d7d3
Add 'jss' and 'default' config patches and configName to rest layout …
CobyPear Aug 5, 2021
5dffd59
Update GraphQL endpoint in RAV sitecore configs
CobyPear Aug 5, 2021
01e691e
Update path to sample2 url - react
CobyPear Aug 10, 2021
f9abcd6
Add api key to graphql header
CobyPear Aug 10, 2021
f5ec4b2
Merge branch 'dev' of github.com:Sitecore/jss into feature/488863
CobyPear Aug 10, 2021
bf0ad20
Update GraphQLData.js to accept language variable - react
CobyPear Aug 10, 2021
8e2976f
Update angular graphql
CobyPear Aug 10, 2021
d202386
Update vue GraphQL components to accept language variable
CobyPear Aug 10, 2021
5ce7a07
Add instance of factory - vue
CobyPear Aug 10, 2021
5296e55
Add sc_apikey header to GraphQLClientFactory - vue
CobyPear Aug 10, 2021
8901b5a
Update jss-create to set credentials - vue
CobyPear Aug 10, 2021
3594bd8
Update node-headless-ssr-experience-edge README
CobyPear Aug 10, 2021
a815e53
Revert analytics: false
CobyPear Aug 10, 2021
f019ec9
Merge branch 'dev' of github.com:Sitecore/jss into feature/488863
CobyPear Aug 12, 2021
e1b92a1
Fix config file formatting
CobyPear Aug 12, 2021
bc96690
Remove sneaky console.log 🐱‍👤
CobyPear Aug 12, 2021
274f983
Create instance of dictionary service - vue
CobyPear Aug 12, 2021
3a66d90
Add mistakenly removed comment from configs
CobyPear Aug 12, 2021
4f7a217
Update misleading comment about sc_apikey header
CobyPear Aug 12, 2021
59e6318
Remove setCredentials
CobyPear Aug 12, 2021
4d8b525
Remove note in headless-ssr-ee readme
CobyPear Aug 12, 2021
297b938
Merge branch 'dev' of github.com:Sitecore/jss into feature/488863
CobyPear Aug 13, 2021
23c7ccd
Hardcode omit/flase credentials for GraphQL client
CobyPear Aug 13, 2021
8de8b31
Actually remove credentials header 🙃
CobyPear Aug 13, 2021
ad59373
Apply proper formatting to XML configs
CobyPear Aug 13, 2021
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
3 changes: 3 additions & 0 deletions packages/sitecore-jss-angular/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export {
constants,
isExperienceEditorActive,
resetExperienceEditorChromes,
DictionaryService,
RestDictionaryService,
GraphQLDictionaryService,
RestLayoutService,
GraphQLLayoutService,
LayoutService,
LayoutServiceData,
LayoutServiceContextData,
Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export {
isExperienceEditorActive,
resetExperienceEditorChromes,
RestDictionaryService,
GraphQLDictionaryService,
DictionaryService,
DictionaryPhrases,
LayoutService,
RestLayoutService,
GraphQLLayoutService,
LayoutServiceData,
LayoutServicePageState,
LayoutServiceContext,
Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export {
resetExperienceEditorChromes,
DictionaryService,
RestDictionaryService,
GraphQLDictionaryService,
LayoutService,
RestLayoutService,
GraphQLLayoutService,
LayoutServiceData,
LayoutServiceContextData,
RouteData,
Expand Down
73 changes: 73 additions & 0 deletions samples/angular/jss-create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const { applyNameToProject } = require('@sitecore-jss/sitecore-jss-cli/dist/cjs/create');

/**
Expand Down Expand Up @@ -35,5 +36,77 @@ module.exports = function createJssProject(argv, nextSteps) {
replaceAngularAppNameInFile('scripts/bootstrap.ts');
replaceAngularAppNameInFile('package.json');

if (!argv.fetchWith) {
nextSteps.push(
`* Did you know you can customize the Angular sample app using ${chalk.green(
'jss create'
)} parameters?`,
`* ${chalk.green(
'--fetchWith {REST|GraphQL}'
)} : Specifies how Sitecore data (layout, dictionary) is fetched. Default is REST.`
);
}

setFetchWith(argv.fetchWith);

return nextSteps;
};

/**
* Sets how Sitecore data (layout, dictionary) is fetched.
* @param {string} [fetchWith] {REST|GraphQL} Default is REST.
*/
function setFetchWith(fetchWith) {
const defaultDsfFile = path.join(__dirname, 'src/app/lib/dictionary-service-factory.ts');
const graphQLDsfFile = path.join(__dirname, 'src/app/lib/dictionary-service-factory.graphql.ts');
const defaultLsfFile = path.join(__dirname, 'src/app/lib/layout-service-factory.ts');
const graphQLLsfFile = path.join(__dirname, 'src/app/lib/layout-service-factory.graphql.ts');
const FetchWith = {
GRAPHQL: 'graphql',
REST: 'rest',
};
let value = fetchWith ? fetchWith.toLowerCase() : FetchWith.REST;

if (value !== FetchWith.REST && value !== FetchWith.GRAPHQL) {
console.warn(chalk.yellow(`Unsupported fetchWith value '${fetchWith}'. Using default 'REST'.`));
value = FetchWith.REST;
}

console.log(chalk.cyan(`Applying ${value === FetchWith.REST ? 'REST' : 'GraphQL'} fetch...`));

switch (value) {
case FetchWith.GRAPHQL:
fs.unlinkSync(defaultDsfFile);
fs.renameSync(graphQLDsfFile, defaultDsfFile);
fs.unlinkSync(defaultLsfFile);
fs.renameSync(graphQLLsfFile, defaultLsfFile);
setCredentials();
break;

case FetchWith.REST:
fs.unlinkSync(graphQLDsfFile);
fs.unlinkSync(graphQLLsfFile);
break;
}
}

/**
* This function will set the 'withCredentials' key in the
* jss-graphql.module.ts file to `false` if --fetchWith graphql
* is passed into the `jss create` command.
*/
function setCredentials() {
ambrauer marked this conversation as resolved.
Show resolved Hide resolved
console.log(chalk.cyan('Setting GraphQL Client credentials...'));

const graphQLClientFactoryFile = path.join(__dirname, 'src/app/jss-graphql.module.ts');

fs.readFile(graphQLClientFactoryFile, 'utf8', (err, data) => {
if (err) return console.log(chalk.red(err));

const result = data.replace(/withCredentials:\strue,/g, 'withCredentials: false,'); // if fetching with GraphQL, credentials must be omitted.

fs.writeFile(graphQLClientFactoryFile, result, 'utf8', (err) => {
if (err) return console.log(chalk.red(err));
});
});
}
2 changes: 1 addition & 1 deletion samples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"sitecoreDistPath": "/dist/JssAngularWeb",
"sitecoreConfigPath": "/App_Config/Include/zzz",
"buildArtifactsPath": "./dist",
"graphQLEndpointPath": "/api/jssangularweb",
"graphQLEndpointPath": "/sitecore/api/graph/edge",
"language": "en"
},
"engines": {
Expand Down
3 changes: 1 addition & 2 deletions samples/angular/scripts/generate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ function addGraphQLConfig(baseConfig: { [key: string]: unknown }) {

// eslint-disable-next-line no-param-reassign
baseConfig.graphQLEndpoint = `${baseConfig.sitecoreApiHost}${
baseConfig.graphQLEndpointPath
}?sc_apikey=${baseConfig.sitecoreApiKey}`;
baseConfig.graphQLEndpointPath}`;
}
112 changes: 32 additions & 80 deletions samples/angular/sitecore/config/JssAngularWeb.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
Normally `jss deploy config` can do this for local development. To manually deploy, or to deploy via CI,
this file can be placed in the `App_Config/Include` folder, or a subfolder of it, within the Sitecore site.
-->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<settings>
<!--
Expand All @@ -29,13 +31,7 @@
but disables workflow and publishing. Before going to production, change the `database`
below to `web` instead of `master`.
-->
<site patch:before="site[@name='website']"
inherits="website"
name="JssAngularWeb"
hostName="JssAngularWeb"
rootPath="/sitecore/content/JssAngularWeb"
startItem="/home"
database="master" />
<site patch:before="site[@name='website']" inherits="website" name="JssAngularWeb" hostName="JssAngularWeb" rootPath="/sitecore/content/JssAngularWeb" startItem="/home" database="master" />
CobyPear marked this conversation as resolved.
Show resolved Hide resolved
</sites>
<javaScriptServices>
<apps>
Expand All @@ -48,12 +44,7 @@

NOTE: graphQLEndpoint enables _Integrated GraphQL_. If not using integrated GraphQL, it can be removed.
-->
<app name="JssAngularWeb"
sitecorePath="/sitecore/content/JssAngularWeb"
inherits="defaults"
useLanguageSpecificLayout="true"
graphQLEndpoint="/api/jssangularweb"
/>
<app name="JssAngularWeb" sitecorePath="/sitecore/content/JssAngularWeb" inherits="defaults" useLanguageSpecificLayout="true" graphQLEndpoint="/sitecore/api/graph/edge" />
</apps>
<!--
IMAGE RESIZING WHITELIST
Expand All @@ -69,76 +60,37 @@
-->
<allowedMediaParams>
<!-- XML element name is arbitary, useful for organizing and patching -->
<styleguide-image-sample>
mw=100,mh=50
<styleguide-image-sample> mw=100,mh=50
</styleguide-image-sample>
<styleguide-image-sample-adaptive>
mw=300
mw=100
<styleguide-image-sample-adaptive> mw=300 mw=100
CobyPear marked this conversation as resolved.
Show resolved Hide resolved
</styleguide-image-sample-adaptive>
</allowedMediaParams>
</javaScriptServices>
<api>
<!--
Define the app's Sitecore GraphQL API endpoint
Note: this can be removed if you are not using GraphQL.
Note: the endpoint must be defined both for integrated and connected type GraphQL queries.
-->
<GraphQL>
<endpoints>
<jssAngularWebGraphQLEndpoint url="/api/jssangularweb" type="Sitecore.Services.GraphQL.Hosting.DatabaseAwareGraphQLEndpoint, Sitecore.Services.GraphQL.NetFxHost" resolve="true">
<url>$(url)</url>

<enabled>true</enabled>
<enableSubscriptions>true</enableSubscriptions>

<!-- lock down the endpoint when deployed to content delivery -->
<graphiql role:require="ContentDelivery">false</graphiql>
<enableSchemaExport role:require="ContentDelivery">false</enableSchemaExport>
<enableStats role:require="ContentDelivery">false</enableStats>
<enableCacheStats role:require="ContentDelivery">false</enableCacheStats>
<disableIntrospection role:require="ContentDelivery">true</disableIntrospection>

<schema hint="list:AddSchemaProvider">
<content type="Sitecore.Services.GraphQL.Content.ContentSchemaProvider, Sitecore.Services.GraphQL.Content">
<!-- scope typed template generation to just this app's templates -->
<templates type="Sitecore.Services.GraphQL.Content.TemplateGeneration.Filters.StandardTemplatePredicate, Sitecore.Services.GraphQL.Content">
<database>context</database>
<paths hint="list:AddIncludedPath">
<templates>/sitecore/templates/Project/JssAngularWeb</templates>
</paths>
<fieldFilter type="Sitecore.Services.GraphQL.Content.TemplateGeneration.Filters.StandardFieldFilter, Sitecore.Services.GraphQL.Content">
<exclusions hint="raw:AddFilter">
<!--
Remove system fields from the API (e.g. __Layout) to keep the schema lean
-->
<exclude name="__*" />
</exclusions>
</fieldFilter>
</templates>

<queries hint="raw:AddQuery">
<!-- enable querying on items via this API -->
<query name="item" type="Sitecore.Services.GraphQL.Content.Queries.ItemQuery, Sitecore.Services.GraphQL.Content" />
</queries>

<fieldTypeMapping ref="/sitecore/api/GraphQL/defaults/content/fieldTypeMappings/standardTypeMapping" />
</content>
</schema>

<!-- Enables the 'jss' graph nodes that are preformatted to use with JSS rendering components, and the datasource resolving queries for JSS -->
<extenders hint="list:AddExtender">
<layoutExtender type="Sitecore.JavaScriptServices.GraphQL.JssExtender, Sitecore.JavaScriptServices.GraphQL" resolve="true" />
</extenders>

<!-- Determines the security of the service. 'publicService' is open to anonymous access, but requires an SSC API key. -->
<security ref="/sitecore/api/GraphQL/defaults/security/publicService" />
<!--
Media URLs resolving
Tells Sitecore to not include the Sitecore server URL as part of the media requests, so that they are instead routed through Next.js rewrites (see next.config.js).
This eliminates exposing the Sitecore server publicly.

<!-- Determines how performance is logged for the service. Defaults are defined in Sitecore.Services.GraphQL.config -->
<performance ref="/sitecore/api/GraphQL/defaults/performance/standard" />
</jssAngularWebGraphQLEndpoint>
</endpoints>
</GraphQL>
</api>
"default" configuration is used for Sitecore GraphQL Edge requests.
"jss" configuration is used for Sitecore Layout Service REST requests.
-->
<layoutService>
<configurations>
<config name="default">
<rendering>
<renderingContentsResolver>
<IncludeServerUrlInMediaUrls>false</IncludeServerUrlInMediaUrls>
</renderingContentsResolver>
</rendering>
</config>
<config name="jss">
<rendering>
<renderingContentsResolver>
<IncludeServerUrlInMediaUrls>false</IncludeServerUrlInMediaUrls>
</renderingContentsResolver>
</rendering>
</config>
</configurations>
</layoutService>
</sitecore>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
# within the context of the IntegratedDemoQuery _operation_. This makes it
# very efficient at gathering data from multiple sources.

query IntegratedDemoQuery($datasource: String!, $contextItem: String!) {
query IntegratedDemoQuery($datasource: String!, $contextItem: String!, $language: String!) {
# Datasource query
# $datasource will always be set to the ID of the rendering's datasource item
# (as long as the GraphQLData helper is used)
datasource(value: $datasource) {
datasource: item(path: $datasource, language: $language) {
id
name
# Strongly-typed querying on known templates is possible!
...on GraphQLIntegratedDemo {
# Single-line text field
sample1 {
# the 'jss' field is a JSON blob that represents the object that
# the 'jsonValue' field is a JSON blob that represents the object that
# should be passed to JSS field rendering helpers (i.e. text, image, link)
jss
jsonValue
value
}
# General Link field
sample2 {
jss
jsonValue
# Structured querying of the field's values is possible
text
target
Expand All @@ -40,7 +40,7 @@ query IntegratedDemoQuery($datasource: String!, $contextItem: String!) {
# Context/route item query
# $contextItem will always be set to the ID of the current context item (the route item)
# (as long as the GraphQLData helper is used)
contextItem: item(path: $contextItem) {
contextItem: item(path: $contextItem, language: $language) {
id
# Get the page title from the app route template
...on AppRoute {
Expand All @@ -50,18 +50,22 @@ query IntegratedDemoQuery($datasource: String!, $contextItem: String!) {
}

# List the children of the current route
children(requirePresentation: true) {
id
# typing fragments can be used anywhere!
# so in this case, we're grabbing the 'pageTitle'
# field on all child route items.
...on AppRoute {
pageTitle {
value
jss
children(hasLayout: true) {
results {
id
# typing fragments can be used anywhere!
# so in this case, we're grabbing the 'pageTitle'
# field on all child route items.
...on AppRoute {
pageTitle {
jsonValue
value
}
}
url{
path
}
}
url(options: { disableLanguageEmbedding: true })
}
}
}
Loading