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

Enhancement/issue 278 graphql plugin #487

Merged
merged 29 commits into from
Mar 19, 2021
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6ea0e05
init commit of WIP with server and graphiql working
thescientist13 Mar 6, 2021
059b890
WIP client side implementation
thescientist13 Mar 6, 2021
21d6647
output message when processing a commonjs file
thescientist13 Mar 6, 2021
2b39aa1
debug statement
thescientist13 Mar 6, 2021
fb86d6a
custom graphql client
thescientist13 Mar 6, 2021
7ca8651
restore graphQL to shelf
thescientist13 Mar 7, 2021
d639daa
refactor shelf
thescientist13 Mar 7, 2021
faf7bba
rollup bundling working
thescientist13 Mar 7, 2021
c9a9090
graphql working in production build
thescientist13 Mar 7, 2021
6018887
upgrade backend apollo 3
thescientist13 Mar 7, 2021
8e46ddd
move and re-enable data unit tests
thescientist13 Mar 11, 2021
3426df8
align server start usage with develop command
thescientist13 Mar 13, 2021
49844de
fixed bug with dangling commas in es-modules-shims
thescientist13 Mar 13, 2021
51584c2
add new config query test case
thescientist13 Mar 13, 2021
d7b98bb
tests for menu query for navigation
thescientist13 Mar 13, 2021
7b9b5f7
clean up
thescientist13 Mar 13, 2021
021135b
add support for children query aliasing
thescientist13 Mar 13, 2021
b50f544
children query specs
thescientist13 Mar 13, 2021
fa09926
cleanup
thescientist13 Mar 13, 2021
15bb49b
graph query test cases and support
thescientist13 Mar 13, 2021
8adc39f
delete old cases
thescientist13 Mar 13, 2021
63628a4
console cleanup
thescientist13 Mar 13, 2021
c8bb1bd
fix label confusion and restore id
thescientist13 Mar 14, 2021
a2edc08
remove frontmatter
thescientist13 Mar 14, 2021
5b15169
refactoring and promisifying
thescientist13 Mar 14, 2021
9b6df9b
graph test with custom frontmatter
thescientist13 Mar 14, 2021
efbb1c9
restore docs
thescientist13 Mar 14, 2021
74b657a
remove example config query
thescientist13 Mar 14, 2021
6164d82
delete commented out code
thescientist13 Mar 19, 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
Prev Previous commit
Next Next commit
restore graphQL to shelf
  • Loading branch information
thescientist13 committed Mar 19, 2021
commit 7ca8651d6f5a9edcded412524770e214a542cf55
6 changes: 3 additions & 3 deletions packages/plugin-graphql/src/index.js
Original file line number Diff line number Diff line change
@@ -63,9 +63,9 @@ class GraphQLResource extends ResourceInterface {
try {
const shimmedBody = body.replace('"imports": {', `
"imports": {
"@greenwood/plugin-graphql/core/client.js": "/node_modules/@greenwood/plugin-graphql/src/core/client.js",
"@greenwood/plugin-graphql/queries/menu.gql": "/node_modules/@greenwood/plugin-graphql/src/queries/menu.gql",
"@greenwood/plugin-graphql/queries/config.gql": "/node_modules/@greenwood/plugin-graphql/src/queries/config.gql",
"@greenwood/plugin-graphql/core/client": "/node_modules/@greenwood/plugin-graphql/src/core/client.js",
"@greenwood/plugin-graphql/queries/menu": "/node_modules/@greenwood/plugin-graphql/src/queries/menu.gql",
"@greenwood/plugin-graphql/queries/config": "/node_modules/@greenwood/plugin-graphql/src/queries/config.gql",
`);

resolve({ body: shimmedBody });
8 changes: 4 additions & 4 deletions packages/plugin-graphql/src/schema/graph.js
Original file line number Diff line number Diff line change
@@ -20,17 +20,17 @@ const getMenuFromGraph = async (root, { name, pathname, orderBy }, context) => {
}

if (route.includes(baseRoute)) {
items.push({ item: { link: route, label: title, index }, children });
items.push({ item: { route, label: title, index }, children });
}
} else {
items.push({ item: { link: route, label: title, index }, children });
items.push({ item: { route, label: title, index }, children });
}
}
});
if (orderBy !== '') {
items = sortMenuItems(items, orderBy);
}
return { item: { label: name, link: 'na' }, children: items };
return { item: { label: name }, children: items };
};

const sortMenuItems = (menuItems, order) => {
@@ -70,7 +70,7 @@ const getParsedHeadingsFromPage = (tableOfContents, headingLevel) => {
tableOfContents.forEach(({ content, slug, lvl }) => {
// make sure we only add heading elements of the same level (h1, h2, h3)
if (lvl === headingLevel) {
children.push({ item: { label: content, link: '#' + slug }, children: [] });
children.push({ item: { label: content, route: '#' + slug }, children: [] });
}
});
}
9 changes: 3 additions & 6 deletions www/components/header/header.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { css, html, LitElement, unsafeCSS } from 'lit-element';
import client from '@greenwood/plugin-graphql/core/client.js';
import MenuQuery from '@greenwood/plugin-graphql/queries/menu.gql';
import ConfigQuery from '@greenwood/plugin-graphql/queries/config.gql';
// import gql from 'graphql-tag';
import client from '@greenwood/plugin-graphql/core/client';
import MenuQuery from '@greenwood/plugin-graphql/queries/menu';
import ConfigQuery from '@greenwood/plugin-graphql/queries/config';
import '@evergreen-wc/eve-container';
import headerCss from './header.css';
// TODO import evergreenLogo from '../../assets/evergreen.svg';
import '../social-icons/social-icons.js';

console.debug('MenuQuery', MenuQuery);
console.debug('ConfigQuery', ConfigQuery);
console.debug('client', client);

class HeaderComponent extends LitElement {

52 changes: 13 additions & 39 deletions www/components/shelf/shelf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css, html, LitElement, unsafeCSS } from 'lit-element';
// import client from '@greenwood/cli/data/client';
// import MenuQuery from '@greenwood/cli/data/queries/menu';
import client from '@greenwood/plugin-graphql/core/client';
import MenuQuery from '@greenwood/plugin-graphql/queries/menu';
import shelfCss from './shelf.css';
import chevronRt from '../icons/chevron-right.js';
import chevronDwn from '../icons/chevron-down.js';
@@ -88,44 +88,18 @@ class Shelf extends LitElement {
}

async fetchShelfData() {
return fetch('/graph.json')
.then(res => res.json())
.then(data => {
return data.filter(page => {
if (page.data.menu && page.data.menu === 'side' && page.route.indexOf(`/${this.page}`) === 0) {
page.label = `${page.label.charAt(0).toUpperCase()}${page.label.slice(1)}`.replace('-', ' ');
page.children = [];

page.data.tableOfContents.forEach(({ content, slug }) => {
page.children.push({
label: content,
route: `#${slug}`
});
});

return page;
}
}).sort((a, b) => {
return a.data.index < b.data.index ? -1 : 1;
});
});
// return await client.query({
// query: MenuQuery,
// variables: {
// name: 'side',
// route: `/${this.page}/`,
// order: 'index_asc'
// }
// });
return await client.query(MenuQuery, {
name: 'side',
route: `/${this.page}/`,
order: 'index_asc'
});
}

async updated(changedProperties) {
if (changedProperties.has('page') && this.page !== '' && this.page !== '/') {
// const response = await this.fetchShelfData();
// this.shelfList = response.data.menu.children;
this.shelfList = await this.fetchShelfData();
// console.debug('this.shelfList', this.shelfList);

const response = await this.fetchShelfData();

this.shelfList = response.data.menu.children;
this.expandRoute(window.location.pathname);
this.requestUpdate();
}
@@ -151,7 +125,7 @@ class Shelf extends LitElement {
${list.map((item) => {
return html`
<li class="${selected ? '' : 'hidden'}">
<a @click=${() => this.handleSubItemSelect(mainRoute, item.route)}>${item.label}</a>
<a @click=${() => this.handleSubItemSelect(mainRoute, item.item.route)}>${item.item.label}</a>
</li>
`;
})}
@@ -172,13 +146,13 @@ class Shelf extends LitElement {
return html`
<li class="list-wrap">
<div>
<a href="${item.route}">${item.label}</a>
<a href="${item.item.route}">${item.item.label}</a>
<a id="${id}" @click="${this.handleShelfClick}"><span class="pointer">${chevron}</span></a>
</div>

<hr/>

${renderListItems(item.route, item.children, item.selected)}
${renderListItems(item.item.route, item.children, item.selected)}
</li>
`;
});