Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-codegen-core

Package Overview
Dependencies
Maintainers
1
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-codegen-core - npm Package Compare versions

Comparing version 0.24.0 to 0.25.0

3

lib/loading.d.ts

@@ -1,4 +0,3 @@

import { DocumentNode, GraphQLSchema } from 'graphql';
import { DocumentNode, GraphQLSchema } from "graphql";
export declare function loadSchema(schemaPath: string): GraphQLSchema;
export declare function loadSchemaFromConfig(projectName: string): GraphQLSchema;
export declare function extractDocumentFromJavascript(content: string, options?: {

@@ -5,0 +4,0 @@ tagName?: string;

@@ -6,3 +6,2 @@ "use strict";

const graphql_1 = require("graphql");
const graphql_config_1 = require("graphql-config");
const errors_1 = require("./errors");

@@ -15,27 +14,10 @@ function loadSchema(schemaPath) {

if (!schemaData.data && !schemaData.__schema) {
throw new errors_1.ToolError('GraphQL schema file should contain a valid GraphQL introspection query result');
throw new errors_1.ToolError("GraphQL schema file should contain a valid GraphQL introspection query result");
}
return graphql_1.buildClientSchema((schemaData.data) ? schemaData.data : schemaData);
return graphql_1.buildClientSchema(schemaData.data ? schemaData.data : schemaData);
}
exports.loadSchema = loadSchema;
function loadSchemaFromConfig(projectName) {
try {
const config = graphql_config_1.getGraphQLProjectConfig('.', projectName);
return config.getSchema();
}
catch (e) {
if (!(e instanceof graphql_config_1.ConfigNotFoundError)) {
throw e;
}
}
const defaultSchemaPath = 'schema.json';
if (localfs_1.fs.existsSync(defaultSchemaPath)) {
return loadSchema('schema.json');
}
throw new errors_1.ToolError(`No GraphQL schema specified. There must either be a .graphqlconfig or a ${defaultSchemaPath} file present, or you must use the --schema option.`);
}
exports.loadSchemaFromConfig = loadSchemaFromConfig;
function maybeCommentedOut(content) {
return (content.indexOf('/*') > -1 && content.indexOf('*/') > -1) ||
content.split('//').length > 1;
return ((content.indexOf("/*") > -1 && content.indexOf("*/") > -1) ||
content.split("//").length > 1);
}

@@ -54,3 +36,3 @@ function filterValidDocuments(documents) {

${document.trim().split('\n')[0]}...
${document.trim().split("\n")[0]}...
`);

@@ -63,24 +45,26 @@ }

function extractDocumentFromJavascript(content, options = {}) {
let tagName = options.tagName || 'gql';
const re = new RegExp(tagName + '\s*`([^`]*)`', 'g');
let tagName = options.tagName || "gql";
const re = new RegExp(tagName + "s*`([^`]*)`", "g");
let match;
let matches = [];
while (match = re.exec(content)) {
const doc = match[1]
.replace(/\${[^}]*}/g, '');
while ((match = re.exec(content))) {
const doc = match[1].replace(/\${[^}]*}/g, "");
matches.push(doc);
}
matches = filterValidDocuments(matches);
const doc = matches.join('\n');
const doc = matches.join("\n");
return doc.length ? doc : null;
}
exports.extractDocumentFromJavascript = extractDocumentFromJavascript;
function loadQueryDocuments(inputPaths, tagName = 'gql') {
const sources = inputPaths.map(inputPath => {
const body = localfs_1.fs.readFileSync(inputPath, 'utf8');
function loadQueryDocuments(inputPaths, tagName = "gql") {
const sources = inputPaths
.map(inputPath => {
const body = localfs_1.fs.readFileSync(inputPath, "utf8");
if (!body) {
return null;
}
if (inputPath.endsWith('.jsx') || inputPath.endsWith('.js')
|| inputPath.endsWith('.tsx') || inputPath.endsWith('.ts')) {
if (inputPath.endsWith(".jsx") ||
inputPath.endsWith(".js") ||
inputPath.endsWith(".tsx") ||
inputPath.endsWith(".ts")) {
const doc = extractDocumentFromJavascript(body.toString(), { tagName });

@@ -90,7 +74,8 @@ return doc ? new graphql_1.Source(doc, inputPath) : null;

return new graphql_1.Source(body, inputPath);
}).filter(source => source);
})
.filter(source => source);
return sources.map(source => graphql_1.parse(source));
}
exports.loadQueryDocuments = loadQueryDocuments;
function loadAndMergeQueryDocuments(inputPaths, tagName = 'gql') {
function loadAndMergeQueryDocuments(inputPaths, tagName = "gql") {
return graphql_1.concatAST(loadQueryDocuments(inputPaths, tagName));

@@ -97,0 +82,0 @@ }

{
"name": "apollo-codegen-core",
"description": "Core generator APIs for Apollo Codegen",
"version": "0.24.0",
"version": "0.25.0",
"main": "./lib/index.js",

@@ -41,4 +41,3 @@ "scripts": {

"common-tags": "^1.5.1",
"core-js": "^2.5.3",
"graphql-config": "^2.0.1"
"core-js": "^2.5.3"
},

@@ -45,0 +44,0 @@ "peerDependencies": {

@@ -1,3 +0,3 @@

import { fs } from './localfs';
import { stripIndents } from 'common-tags';
import { fs } from "./localfs";
import { stripIndents } from "common-tags";

@@ -11,11 +11,6 @@ import {

GraphQLSchema
} from 'graphql';
} from "graphql";
import {
getGraphQLProjectConfig,
ConfigNotFoundError
} from 'graphql-config'
import { ToolError } from "./errors";
import { ToolError } from './errors'
export function loadSchema(schemaPath: string): GraphQLSchema {

@@ -28,29 +23,14 @@ if (!fs.existsSync(schemaPath)) {

if (!schemaData.data && !schemaData.__schema) {
throw new ToolError('GraphQL schema file should contain a valid GraphQL introspection query result');
throw new ToolError(
"GraphQL schema file should contain a valid GraphQL introspection query result"
);
}
return buildClientSchema((schemaData.data) ? schemaData.data : schemaData);
return buildClientSchema(schemaData.data ? schemaData.data : schemaData);
}
export function loadSchemaFromConfig(projectName: string): GraphQLSchema {
try {
const config = getGraphQLProjectConfig('.', projectName);
return config.getSchema();
} catch (e) {
if (!(e instanceof ConfigNotFoundError)) {
throw e;
}
}
const defaultSchemaPath = 'schema.json';
if (fs.existsSync(defaultSchemaPath)) {
return loadSchema('schema.json');
}
throw new ToolError(`No GraphQL schema specified. There must either be a .graphqlconfig or a ${defaultSchemaPath} file present, or you must use the --schema option.`);
}
function maybeCommentedOut(content: string) {
return (content.indexOf('/*') > -1 && content.indexOf('*/') > -1) ||
content.split('//').length > 1;
return (
(content.indexOf("/*") > -1 && content.indexOf("*/") > -1) ||
content.split("//").length > 1
);
}

@@ -70,3 +50,3 @@

${document.trim().split('\n')[0]}...
${document.trim().split("\n")[0]}...
`

@@ -84,39 +64,46 @@ );

options: {
tagName?: string,
tagName?: string;
} = {}
): string | null {
let tagName = options.tagName || 'gql';
let tagName = options.tagName || "gql";
const re = new RegExp(tagName + '\s*`([^`]*)`', 'g');
const re = new RegExp(tagName + "s*`([^`]*)`", "g");
let match;
let matches = [];
while(match = re.exec(content)) {
const doc = match[1]
.replace(/\${[^}]*}/g, '')
while ((match = re.exec(content))) {
const doc = match[1].replace(/\${[^}]*}/g, "");
matches.push(doc)
matches.push(doc);
}
matches = filterValidDocuments(matches);
const doc = matches.join('\n')
const doc = matches.join("\n");
return doc.length ? doc : null;
}
export function loadQueryDocuments(inputPaths: string[], tagName: string = 'gql'): DocumentNode[] {
const sources = inputPaths.map(inputPath => {
const body = fs.readFileSync(inputPath, 'utf8');
if (!body) {
return null;
}
export function loadQueryDocuments(
inputPaths: string[],
tagName: string = "gql"
): DocumentNode[] {
const sources = inputPaths
.map(inputPath => {
const body = fs.readFileSync(inputPath, "utf8");
if (!body) {
return null;
}
if (inputPath.endsWith('.jsx') || inputPath.endsWith('.js')
|| inputPath.endsWith('.tsx') || inputPath.endsWith('.ts')
) {
const doc = extractDocumentFromJavascript(body.toString(), { tagName });
return doc ? new Source(doc, inputPath) : null;
}
if (
inputPath.endsWith(".jsx") ||
inputPath.endsWith(".js") ||
inputPath.endsWith(".tsx") ||
inputPath.endsWith(".ts")
) {
const doc = extractDocumentFromJavascript(body.toString(), { tagName });
return doc ? new Source(doc, inputPath) : null;
}
return new Source(body, inputPath);
}).filter(source => source);
return new Source(body, inputPath);
})
.filter(source => source);

@@ -126,5 +113,7 @@ return (sources as Source[]).map(source => parse(source));

export function loadAndMergeQueryDocuments(inputPaths: string[], tagName: string = 'gql'): DocumentNode {
export function loadAndMergeQueryDocuments(
inputPaths: string[],
tagName: string = "gql"
): DocumentNode {
return concatAST(loadQueryDocuments(inputPaths, tagName));
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc