diff --git a/gatsby-config.js b/gatsby-config.js index 1b17d9db3..8b53f1d8a 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -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'; @@ -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; + }) } }, { diff --git a/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js b/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js index 639513d57..45ed4085d 100644 --- a/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js +++ b/plugins/gatsby-plugin-apollo-client-api-doc/gatsby-node.js @@ -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}); diff --git a/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js b/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js index 66c8d82d6..b3b5875ac 100644 --- a/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js +++ b/plugins/gatsby-plugin-apollo-client-api-doc/parseTs.js @@ -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) {