Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support and infra for Node 4, 6, and 8. #63

Merged
merged 6 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
version: 2
jobs:
build:
docker:
- image: circleci/node
references:
run_tests: &run_tests
steps:
- checkout
- run: sudo npm install -g yarn semantic-release@12.0.0
- run: sudo npm install -g yarn
- run: yarn install
- run:
name: test
Expand All @@ -21,7 +19,41 @@ jobs:
- store_artifacts:
path: coverage
prefix: coverage

jobs:
build-node4:
docker:
- image: circleci/node:4
<<: *run_tests
build-node6:
docker:
- image: circleci/node:6
<<: *run_tests
build-node8:
docker:
- image: circleci/node
<<: *run_tests
release:
docker:
- image: circleci/node
steps:
- checkout
- run: sudo npm install -g yarn semantic-release@12.0.0
- run: yarn install
- run: semantic-release
- run: yarn docs
# needs proper NOW setup first
# - run: yarn docs:publish

workflows:
version: 2
build:
jobs:
- build-node4
- build-node6
- build-node8
- release:
requires:
- build-node4
- build-node6
- build-node8
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "graphql-import",
"version": "0.0.0-semantic-release",
"engines": {
"node": ">=4.0.0"
},
"license": "MIT",
"repository": "git@github.com:graphcool/graphql-import.git",
"files": [
Expand Down
6 changes: 3 additions & 3 deletions src/definition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { keyBy, uniqBy } from 'lodash'
import { keyBy, uniqBy, includes } from 'lodash'
import {
DocumentNode,
TypeDefinitionNode,
Expand Down Expand Up @@ -147,7 +147,7 @@ function collectNewTypeDefinitions(
// collect missing argument input types
if (
!definitionPool.some(d => d.name.value === nodeTypeName) &&
!builtinTypes.includes(nodeTypeName)
!includes(builtinTypes, nodeTypeName)
) {
const argTypeMatch = schemaMap[nodeTypeName]
if (!argTypeMatch) {
Expand All @@ -165,7 +165,7 @@ function collectNewTypeDefinitions(
const directiveName = directive.name.value
if (
!definitionPool.some(d => d.name.value === directiveName) &&
!builtinDirectives.includes(directiveName)
!includes(builtinDirectives, directiveName)
) {
const directive = schemaMap[directiveName] as DirectiveDefinitionNode
if (!directive) {
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs'
import { DefinitionNode, parse, print, TypeDefinitionNode, GraphQLObjectType, ObjectTypeDefinitionNode, DocumentNode, Kind } from 'graphql'
import { flatten, groupBy } from 'lodash'
import { flatten, groupBy, includes } from 'lodash'
import * as path from 'path'

import {
Expand Down Expand Up @@ -88,13 +88,13 @@ export function importSchema(schema: string, schemas?: { [key: string]: string }
// And should always be in the first set, to make sure they
// are not filtered out.
const typesToFilter = ['Query', 'Mutation', 'Subscription']
const firstTypes = flatten(typeDefinitions).filter(d => typesToFilter.includes(d.name.value))
const otherFirstTypes = typeDefinitions[0].filter(d => !typesToFilter.includes(d.name.value))
const firstTypes = flatten(typeDefinitions).filter(d => includes(typesToFilter, d.name.value))
const otherFirstTypes = typeDefinitions[0].filter(d => !includes(typesToFilter, d.name.value))
const firstSet = otherFirstTypes.concat(firstTypes)
const processedTypeNames = []
const mergedFirstTypes = []
for (const type of firstSet) {
if (!processedTypeNames.includes(type.name.value)) {
if (!includes(processedTypeNames, type.name.value)) {
processedTypeNames.push(type.name.value)
mergedFirstTypes.push(type)
} else {
Expand Down Expand Up @@ -232,10 +232,10 @@ function filterImportedDefinitions(

const filteredDefinitions = filterTypeDefinitions(typeDefinitions)

if (imports.includes('*')) {
if (includes(imports, '*')) {
return filteredDefinitions
} else {
const result = filteredDefinitions.filter(d => imports.map(i => i.split('.')[0]).includes(d.name.value))
const result = filteredDefinitions.filter(d => includes(imports.map(i => i.split('.')[0]), d.name.value))
const fieldImports = imports
.filter(i => i.split('.').length > 1)
const groupedFieldImports = groupBy(fieldImports, x => x.split('.')[0])
Expand All @@ -244,7 +244,7 @@ function filterImportedDefinitions(
const fields = groupedFieldImports[rootType].map(x => x.split('.')[1]);
(filteredDefinitions.find(def => def.name.value === rootType) as ObjectTypeDefinitionNode).fields =
(filteredDefinitions.find(def => def.name.value === rootType) as ObjectTypeDefinitionNode).fields
.filter(f => fields.includes(f.name.value) || fields.includes('*'))
.filter(f => includes(fields, f.name.value) || includes(fields, '*'))
}

return result
Expand All @@ -270,6 +270,6 @@ function filterTypeDefinitions(
'InputObjectTypeDefinition'
]
return definitions
.filter(d => validKinds.includes(d.kind))
.filter(d => includes(validKinds, d.kind))
.map(d => d as ValidDefinitionNode)
}