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

@graphql-tools/graphql-file-loader

Package Overview
Dependencies
Maintainers
3
Versions
1059
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/graphql-file-loader - npm Package Compare versions

Comparing version 5.0.1-alpha-ac91d12.0 to 5.0.1-alpha-af24cb2.0

51

index.cjs.js

@@ -6,4 +6,12 @@ 'use strict';

const utils = require('@graphql-tools/utils');
const path = require('path');
const fsExtra = require('fs-extra');
const process = require('process');
const _import = require('@graphql-tools/import');
const FILE_EXTENSIONS = ['.gql', '.gqls', '.graphql', '.graphqls'];
function isGraphQLImportFile(rawSDL) {
const trimmedRawSDL = rawSDL.trim();
return trimmedRawSDL.startsWith('# import') || trimmedRawSDL.startsWith('#import');
}
class GraphQLFileLoader {

@@ -14,13 +22,15 @@ loaderId() {

async canLoad(pointer, options) {
return this.canLoadSync(pointer, options);
if (utils.isValidPath(pointer)) {
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd, pointer);
return new Promise(resolve => fsExtra.exists(normalizedFilePath, resolve));
}
}
return false;
}
canLoadSync(pointer, options) {
if (utils.isValidPath(pointer) && options.path && options.fs) {
const { resolve, isAbsolute } = options.path;
if (utils.isValidPath(pointer)) {
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || process.cwd(), pointer);
const { existsSync } = options.fs;
if (existsSync(normalizedFilePath)) {
return true;
}
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd, pointer);
return fsExtra.existsSync(normalizedFilePath);
}

@@ -31,10 +41,23 @@ }

async load(pointer, options) {
return this.loadSync(pointer, options);
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd, pointer);
const rawSDL = await fsExtra.readFile(normalizedFilePath, { encoding: 'utf8' });
if (isGraphQLImportFile(rawSDL)) {
return {
location: pointer,
document: _import.processImport(pointer, options.cwd),
};
}
return utils.parseGraphQLSDL(pointer, rawSDL.trim(), options);
}
loadSync(pointer, options) {
const { resolve, isAbsolute } = options.path;
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || process.cwd(), pointer);
const { readFileSync } = options.fs;
const rawSDL = readFileSync(normalizedFilePath, 'utf-8').trim();
return utils.parseGraphQLSDL(pointer, rawSDL, options);
const cwd = options.cwd || process.cwd();
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(cwd, pointer);
const rawSDL = fsExtra.readFileSync(normalizedFilePath, { encoding: 'utf8' });
if (isGraphQLImportFile(rawSDL)) {
return {
location: pointer,
document: _import.processImport(pointer, options.cwd),
};
}
return utils.parseGraphQLSDL(pointer, rawSDL.trim(), options);
}

@@ -41,0 +64,0 @@ }

import { Source, UniversalLoader, DocumentPointerSingle, SchemaPointerSingle, SingleFileOptions } from '@graphql-tools/utils';
export interface GraphQLFileLoaderOptions extends SingleFileOptions {
fs?: typeof import('fs');
path?: typeof import('path');
}

@@ -6,0 +4,0 @@ export declare class GraphQLFileLoader implements UniversalLoader<GraphQLFileLoaderOptions> {

import { isValidPath, parseGraphQLSDL } from '@graphql-tools/utils';
import { isAbsolute, resolve } from 'path';
import { exists, existsSync, readFile, readFileSync } from 'fs-extra';
import { cwd } from 'process';
import { processImport } from '@graphql-tools/import';
const FILE_EXTENSIONS = ['.gql', '.gqls', '.graphql', '.graphqls'];
function isGraphQLImportFile(rawSDL) {
const trimmedRawSDL = rawSDL.trim();
return trimmedRawSDL.startsWith('# import') || trimmedRawSDL.startsWith('#import');
}
class GraphQLFileLoader {

@@ -9,13 +17,15 @@ loaderId() {

async canLoad(pointer, options) {
return this.canLoadSync(pointer, options);
if (isValidPath(pointer)) {
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd, pointer);
return new Promise(resolve => exists(normalizedFilePath, resolve));
}
}
return false;
}
canLoadSync(pointer, options) {
if (isValidPath(pointer) && options.path && options.fs) {
const { resolve, isAbsolute } = options.path;
if (isValidPath(pointer)) {
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || process.cwd(), pointer);
const { existsSync } = options.fs;
if (existsSync(normalizedFilePath)) {
return true;
}
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd, pointer);
return existsSync(normalizedFilePath);
}

@@ -26,10 +36,23 @@ }

async load(pointer, options) {
return this.loadSync(pointer, options);
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd, pointer);
const rawSDL = await readFile(normalizedFilePath, { encoding: 'utf8' });
if (isGraphQLImportFile(rawSDL)) {
return {
location: pointer,
document: processImport(pointer, options.cwd),
};
}
return parseGraphQLSDL(pointer, rawSDL.trim(), options);
}
loadSync(pointer, options) {
const { resolve, isAbsolute } = options.path;
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || process.cwd(), pointer);
const { readFileSync } = options.fs;
const rawSDL = readFileSync(normalizedFilePath, 'utf-8').trim();
return parseGraphQLSDL(pointer, rawSDL, options);
const cwd$1 = options.cwd || cwd();
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(cwd$1, pointer);
const rawSDL = readFileSync(normalizedFilePath, { encoding: 'utf8' });
if (isGraphQLImportFile(rawSDL)) {
return {
location: pointer,
document: processImport(pointer, options.cwd),
};
}
return parseGraphQLSDL(pointer, rawSDL.trim(), options);
}

@@ -36,0 +59,0 @@ }

{
"name": "@graphql-tools/graphql-file-loader",
"version": "5.0.1-alpha-ac91d12.0",
"version": "5.0.1-alpha-af24cb2.0",
"description": "A set of utils for faster development of GraphQL tools",

@@ -9,3 +9,5 @@ "peerDependencies": {

"dependencies": {
"@graphql-tools/utils": "5.0.1-alpha-ac91d12.0",
"@graphql-tools/import": "5.0.1-alpha-af24cb2.0",
"@graphql-tools/utils": "5.0.1-alpha-af24cb2.0",
"fs-extra": "9.0.0",
"tslib": "1.11.1"

@@ -22,2 +24,5 @@ },

},
"devDependencies": {
"@types/fs-extra": "8.1.0"
},
"publishConfig": {

@@ -24,0 +29,0 @@ "access": "public"

Sorry, the diff of this file is not supported yet

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