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.22.0 to 0.23.0

29

lib/compiler/index.js

@@ -19,3 +19,3 @@ "use strict";

case graphql_1.Kind.FRAGMENT_DEFINITION:
const fragment = compiler.compileFragment(definition);
const fragment = compiler.compileFragment(definition, false);
fragments[fragment.fragmentName] = fragment;

@@ -87,6 +87,6 @@ break;

rootType,
selectionSet: this.compileSelectionSet(operationDefinition.selectionSet, rootType)
selectionSet: this.compileSelectionSet(operationDefinition.selectionSet, rootType, false)
};
}
compileFragment(fragmentDefinition) {
compileFragment(fragmentDefinition, isClient) {
const fragmentName = fragmentDefinition.name.value;

@@ -101,16 +101,17 @@ const filePath = graphql_2.filePathForNode(fragmentDefinition);

type,
selectionSet: this.compileSelectionSet(fragmentDefinition.selectionSet, type)
selectionSet: this.compileSelectionSet(fragmentDefinition.selectionSet, type, isClient)
};
}
compileSelectionSet(selectionSetNode, parentType, possibleTypes = this.possibleTypesForType(parentType), visitedFragments = new Set()) {
compileSelectionSet(selectionSetNode, parentType, isClient, possibleTypes = this.possibleTypesForType(parentType), visitedFragments = new Set()) {
return {
possibleTypes,
selections: selectionSetNode.selections
.map(selectionNode => wrapInBooleanConditionsIfNeeded(this.compileSelection(selectionNode, parentType, possibleTypes, visitedFragments), selectionNode, possibleTypes))
.map(selectionNode => wrapInBooleanConditionsIfNeeded(this.compileSelection(selectionNode, parentType, possibleTypes, visitedFragments, isClient), selectionNode, possibleTypes))
.filter(x => x)
};
}
compileSelection(selectionNode, parentType, possibleTypes, visitedFragments) {
compileSelection(selectionNode, parentType, possibleTypes, visitedFragments, isClient) {
switch (selectionNode.kind) {
case graphql_1.Kind.FIELD: {
const fieldIsClient = (selectionNode.directives || []).some(d => d.name.value == "client");
const name = selectionNode.name.value;

@@ -124,2 +125,12 @@ const alias = selectionNode.alias ? selectionNode.alias.value : undefined;

}
if (fieldDef.astNode && fieldDef.astNode.__client && !(isClient || fieldIsClient)) {
throw new graphql_1.GraphQLError(`Cannot query client-side field "${name}" on type "${String(parentType)}" without @client directive`, [
selectionNode
]);
}
if (!(fieldDef.astNode && fieldDef.astNode.__client) && (isClient || fieldIsClient)) {
throw new graphql_1.GraphQLError(`Cannot query server-side field "${name}" on type "${String(parentType)}" with @client directive`, [
selectionNode
]);
}
const fieldType = fieldDef.type;

@@ -157,3 +168,3 @@ const unmodifiedFieldType = graphql_1.getNamedType(fieldType);

}
field.selectionSet = this.compileSelectionSet(selectionNode.selectionSet, unmodifiedFieldType);
field.selectionSet = this.compileSelectionSet(selectionNode.selectionSet, unmodifiedFieldType, isClient || fieldIsClient);
}

@@ -169,3 +180,3 @@ return field;

type,
selectionSet: this.compileSelectionSet(selectionNode.selectionSet, type, possibleTypesForTypeCondition)
selectionSet: this.compileSelectionSet(selectionNode.selectionSet, type, isClient, possibleTypesForTypeCondition)
};

@@ -172,0 +183,0 @@ }

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

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

"watch": "tsc -w -p .",
"test": "./node_modules/.bin/jest"
"test": "./node_modules/.bin/jest",
"prepack": "npm run build"
},

@@ -14,0 +15,0 @@ "repository": {

@@ -145,3 +145,3 @@ import {

case Kind.FRAGMENT_DEFINITION:
const fragment = compiler.compileFragment(definition);
const fragment = compiler.compileFragment(definition, false);
fragments[fragment.fragmentName] = fragment;

@@ -239,7 +239,7 @@ break;

rootType,
selectionSet: this.compileSelectionSet(operationDefinition.selectionSet, rootType)
selectionSet: this.compileSelectionSet(operationDefinition.selectionSet, rootType, false)
};
}
compileFragment(fragmentDefinition: FragmentDefinitionNode): Fragment {
compileFragment(fragmentDefinition: FragmentDefinitionNode, isClient: boolean): Fragment {
const fragmentName = fragmentDefinition.name.value;

@@ -257,3 +257,3 @@

type,
selectionSet: this.compileSelectionSet(fragmentDefinition.selectionSet, type)
selectionSet: this.compileSelectionSet(fragmentDefinition.selectionSet, type, isClient)
};

@@ -265,2 +265,3 @@ }

parentType: GraphQLCompositeType,
isClient: boolean,
possibleTypes: GraphQLObjectType[] = this.possibleTypesForType(parentType),

@@ -274,3 +275,3 @@ visitedFragments: Set<string> = new Set()

wrapInBooleanConditionsIfNeeded(
this.compileSelection(selectionNode, parentType, possibleTypes, visitedFragments),
this.compileSelection(selectionNode, parentType, possibleTypes, visitedFragments, isClient),
selectionNode,

@@ -288,6 +289,8 @@ possibleTypes

possibleTypes: GraphQLObjectType[],
visitedFragments: Set<string>
visitedFragments: Set<string>,
isClient: boolean
): Selection | null {
switch (selectionNode.kind) {
case Kind.FIELD: {
const fieldIsClient = (selectionNode.directives || []).some(d => d.name.value == "client");
const name = selectionNode.name.value;

@@ -303,2 +306,14 @@ const alias = selectionNode.alias ? selectionNode.alias.value : undefined;

if (fieldDef.astNode && (fieldDef.astNode as any).__client && !(isClient || fieldIsClient)) {
throw new GraphQLError(`Cannot query client-side field "${name}" on type "${String(parentType)}" without @client directive`, [
selectionNode
]);
}
if (!(fieldDef.astNode && (fieldDef.astNode as any).__client) && (isClient || fieldIsClient)) {
throw new GraphQLError(`Cannot query server-side field "${name}" on type "${String(parentType)}" with @client directive`, [
selectionNode
]);
}
const fieldType = fieldDef.type;

@@ -349,3 +364,4 @@ const unmodifiedFieldType = getNamedType(fieldType);

selectionNode.selectionSet as SelectionSetNode,
unmodifiedFieldType
unmodifiedFieldType,
isClient || fieldIsClient
);

@@ -367,2 +383,3 @@ }

type,
isClient,
possibleTypesForTypeCondition

@@ -369,0 +386,0 @@ )

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