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

support multiple docmodels #837

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {query, transformer} = require('./algolia');
const yaml = require('js-yaml');
const fs = require('fs');
const remoteSources = require('./sources/remote');
const {join} = require('path');
const {join, basename} = require('path');

const isProduction = process.env.CONTEXT === 'production';

Expand Down Expand Up @@ -103,9 +103,17 @@ const plugins = [
{
resolve: 'gatsby-plugin-apollo-client-api-doc',
options: {
file: isSingleDocset
? join(__dirname, 'local/public/client.api.json')
: 'https://apollo-client-docs.netlify.app/client.api.json'
files: [
'https://apollo-client-docs.netlify.app/client.api.json',
'https://main--apollo-client-nextjs-docmodel.netlify.app/client-react-streaming.api.json',
'https://main--apollo-client-nextjs-docmodel.netlify.app/experimental-nextjs-app-support.api.json'
].map(url => {
if (isSingleDocset) {
const local = join(__dirname, 'local/public/', basename(url));
if (fs.existsSync(local)) return local;
}
return url;
})
}
},
{
Expand Down
30 changes: 16 additions & 14 deletions plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ const reactPreset = require('@babel/preset-react');
/** @type {import("gatsby").GatsbyNode['sourceNodes']} */
exports.sourceNodes = async (api, options) => {
const tempDir = fs.mkdtempSync('api-model');
try {
let {file} = /** @type {{file:string}} */ (options);
const {files} = /** @type {{files:string[]}} */ (options);

if (file.includes('://')) {
console.info('downloading api doc from url', file);
const request = await fetch(file);
const contents = await request.text();
file = path.join(tempDir, 'api.json');
fs.writeFileSync(file, contents);
}
if (fs.existsSync(file)) {
console.info('loading api doc from file', file);
loadApiDoc(file, api);
} else {
console.info('api doc file not found, skipping', file);
try {
for (let file of files) {
if (file.includes('://')) {
console.info('downloading api doc from url', file);
const request = await fetch(file);
const contents = await request.text();
file = path.join(tempDir, 'api.json');
fs.writeFileSync(file, contents);
}
if (fs.existsSync(file)) {
console.info('loading api doc from file', file);
loadApiDoc(file, api);
} else {
console.info('api doc file not found, skipping', file);
}
}
} finally {
fs.rmSync(tempDir, {recursive: true});
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const parseKeyword = getRegexParser(

const parseNumber = getRegexParser(/^\d+(\.\d+)?/, 'Number');

const parseIdentifier = getRegexParser(/^[a-zA-Z]\w*/, 'Identifier');
const parseIdentifier = getRegexParser(/^[a-zA-Z][$\w]*/, 'Identifier');

/** @type {ParserFn} */
function parseString(code, index) {
Expand Down