refactor: cli plugin apollo 0.14.0

This commit is contained in:
Guillaume Chau
2018-06-29 14:47:45 +02:00
parent 6ff9d980ce
commit 3997f9e62b
20 changed files with 798 additions and 1227 deletions
+1
View File
@@ -1,3 +1,4 @@
node_modules/
dist/
tests/
schema.graphql
+1 -2
View File
@@ -2,8 +2,7 @@
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"graphql"
"vue"
],
"eslint.enable": true
}
+1 -1
View File
@@ -14,7 +14,7 @@
"prepublishOnly": "npm run test && npm run build",
"dev": "nodemon --exec 'npm run build:es' --watch src",
"test": "npm run test:eslint && npm run test:types",
"test:eslint": "eslint --ext .js src",
"test:eslint": "eslint --ext .js src && eslint --ext .js,.vue,.gql tests/demo/src",
"test:types": "tsc -p types/test",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
+2 -1
View File
@@ -14,7 +14,8 @@ module.exports = {
'graphql/template-strings': [
'error',
{
env: 'literal'
env: 'literal',
projectName: 'app',
}
],
'comma-dangle': ['error', 'always-multiline'],
-3
View File
@@ -1,3 +0,0 @@
{
"schemaPath": "./src/graphql-api/schema.graphql"
}
+8
View File
@@ -0,0 +1,8 @@
projects:
app:
schemaPath: apollo-server/schema.graphql
includes:
- '**/*.gql'
extensions:
endpoints:
default: 'http://localhost:4000/graphql'
@@ -4,10 +4,11 @@ const users = require('./connectors/users')
// req => Query
// connection => Subscription
// eslint-disable-next-line no-unused-vars
module.exports = (req, wsConnection) => {
module.exports = ({ req, connection }) => {
console.log('connection:', connection)
let rawToken
if (req) rawToken = req.get('Authorization')
if (wsConnection) rawToken = wsConnection.authorization
if (connection) rawToken = connection.authorization
const token = rawToken ? JSON.parse(rawToken) : null
let userId
@@ -15,6 +16,8 @@ module.exports = (req, wsConnection) => {
userId = token.userId
}
console.log('token:', token, 'userId:', userId)
return {
token,
userId,
@@ -5,6 +5,7 @@ module.exports = class PrivateDirective extends SchemaDirectiveVisitor {
visitFieldDefinition (field) {
const { resolve = defaultFieldResolver } = field
field.resolve = (root, args, context, info) => {
console.log(info.fieldName, context.userId)
if (!context.userId) throw new Error('Unauthorized')
return resolve(root, args, context, info)
}
+3 -4
View File
@@ -7,15 +7,14 @@
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:e2e": "vue-cli-service test:e2e",
"graphql-api": "vue-cli-service graphql-api",
"run-graphql-api": "vue-cli-service run-graphql-api"
"apollo": "vue-cli-service apollo:watch",
"apollo:run": "vue-cli-service apollo:run"
},
"dependencies": {
"graphql-type-json": "^0.2.1",
"marked": "^0.4.0",
"shortid": "^2.2.8",
"vue": "^2.5.16",
"vue-apollo": "^3.0.0-beta.16",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
@@ -29,7 +28,7 @@
"graphql-tag": "^2.5.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vue-cli-plugin-apollo": "^0.13.4",
"vue-cli-plugin-apollo": "^0.14.2",
"vue-template-compiler": "^2.5.16"
},
"browserslist": [
+400 -425
View File
File diff suppressed because it is too large Load Diff
+376 -789
View File
File diff suppressed because it is too large Load Diff