Skip to content

Commit

Permalink
Rebuild the CLI
Browse files Browse the repository at this point in the history
First off, if you have reached this point in the git history, I'm sorry.
Hopefully this will never be found because I will have had time to split
this commit into about 10 smaller commits, but alas Summit is days away
and all of this needed to work. Forgive me team as I have sinned and
created a monster commit. It was to ease the nasty rebase awaiting
me from Maritjn and because there was almost no parital state at
any working time.

- with deep sadness, jbaxleyiii
  • Loading branch information
James Baxley authored and martijnwalraven committed Nov 4, 2018
1 parent ed97d4b commit d2d73f9
Show file tree
Hide file tree
Showing 83 changed files with 2,212 additions and 4,908 deletions.
307 changes: 237 additions & 70 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,25 @@
"@fancy-test/nock": "^0.1.1",
"@oclif/dev-cli": "^1.17.0",
"@oclif/test": "^1.2.0",
"@types/babel-types": "^7.0.4",
"@types/babel__generator": "^7.0.0",
"@types/babel-types": "^7.0.4",
"@types/chai": "^4.1.4",
"@types/common-tags": "^1.4.0",
"@types/cosmiconfig": "^5.0.3",
"@types/globby": "^8.0.0",
"@types/graphql": "^14.0.2",
"@types/inflected": "^1.1.29",
"@types/jest": "^23.3.1",
"@types/listr": "^0.13.0",
"@types/lodash": "^4.14.109",
"@types/minimatch": "^3.0.3",
"@types/nock": "^9.3.0",
"@types/node-fetch": "^2.1.2",
"@types/node": "^10.9.4",
"@types/react": "^16.4.13",
"@types/react-dom": "^16.0.7",
"@types/react": "^16.4.13",
"@types/recursive-readdir": "^2.2.0",
"@types/rimraf": "^2.0.2",
"@types/ws": "^6.0.0",
"babel-loader": "^7.1.2",
"babel-preset-react-app": "^3.1.2",
Expand Down
52 changes: 7 additions & 45 deletions packages/apollo-codegen-core/src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function compileToIR(
operations[operation.operationName] = operation;
break;
case Kind.FRAGMENT_DEFINITION:
const fragment = compiler.compileFragment(definition, false);
const fragment = compiler.compileFragment(definition);
fragments[fragment.fragmentName] = fragment;
break;
}
Expand Down Expand Up @@ -248,16 +248,12 @@ class Compiler {
rootType,
selectionSet: this.compileSelectionSet(
operationDefinition.selectionSet,
rootType,
false
rootType
)
};
}

compileFragment(
fragmentDefinition: FragmentDefinitionNode,
isClient: boolean
): Fragment {
compileFragment(fragmentDefinition: FragmentDefinitionNode): Fragment {
const fragmentName = fragmentDefinition.name.value;

const filePath = filePathForNode(fragmentDefinition);
Expand All @@ -275,16 +271,14 @@ class Compiler {
type,
selectionSet: this.compileSelectionSet(
fragmentDefinition.selectionSet,
type,
isClient
type
)
};
}

compileSelectionSet(
selectionSetNode: SelectionSetNode,
parentType: GraphQLCompositeType,
isClient: boolean,
possibleTypes: GraphQLObjectType[] = this.possibleTypesForType(parentType),
visitedFragments: Set<string> = new Set()
): SelectionSet {
Expand All @@ -297,8 +291,7 @@ class Compiler {
selectionNode,
parentType,
possibleTypes,
visitedFragments,
isClient
visitedFragments
),
selectionNode,
possibleTypes
Expand All @@ -312,14 +305,10 @@ class Compiler {
selectionNode: SelectionNode,
parentType: GraphQLCompositeType,
possibleTypes: GraphQLObjectType[],
visitedFragments: Set<string>,
isClient: boolean
visitedFragments: Set<string>
): Selection | null {
switch (selectionNode.kind) {
case Kind.FIELD: {
const fieldIsClient = (selectionNode.directives || []).some(
d => d.name.value == "client"
);
const name = selectionNode.name.value;
const alias = selectionNode.alias
? selectionNode.alias.value
Expand All @@ -333,31 +322,6 @@ class Compiler {
);
}

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) &&
fieldIsClient
) {
throw new GraphQLError(
`Cannot query server-side field "${name}" on type "${String(
parentType
)}" with @client directive`,
[selectionNode]
);
}

const fieldType = fieldDef.type;
const unmodifiedFieldType = getNamedType(fieldType);

Expand Down Expand Up @@ -408,8 +372,7 @@ class Compiler {

field.selectionSet = this.compileSelectionSet(
selectionNode.selectionSet as SelectionSetNode,
unmodifiedFieldType,
isClient || fieldIsClient
unmodifiedFieldType
);
}
return field;
Expand All @@ -428,7 +391,6 @@ class Compiler {
selectionSet: this.compileSelectionSet(
selectionNode.selectionSet,
type,
isClient,
possibleTypesForTypeCondition
)
};
Expand Down
Loading

0 comments on commit d2d73f9

Please sign in to comment.