mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 18:11:40 -05:00
remove apollo packages
This commit is contained in:
parent
9992f0063e
commit
e8714af111
6 changed files with 0 additions and 306 deletions
|
@ -1 +0,0 @@
|
|||
Nova Apollo Client & Server package. It handles the data layer of Nova.
|
|
@ -1,89 +0,0 @@
|
|||
// note(oct. 28, 2016)
|
||||
// by-pass the meteor integration to use the features of apollo-client 0.5.x / graphql-server 0.4.x
|
||||
|
||||
// -------
|
||||
// start of main-client from apollostack/meteor-integration
|
||||
|
||||
import { createNetworkInterface } from 'apollo-client';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import 'isomorphic-fetch';
|
||||
|
||||
const defaultNetworkInterfaceConfig = {
|
||||
path: '/graphql',
|
||||
options: {},
|
||||
};
|
||||
|
||||
export const createMeteorNetworkInterface = (givenConfig) => {
|
||||
const config = _.extend(defaultNetworkInterfaceConfig, givenConfig);
|
||||
|
||||
// absoluteUrl adds a '/', so let's remove it first
|
||||
let path = config.path;
|
||||
if (path[0] === '/') {
|
||||
path = path.slice(1);
|
||||
}
|
||||
|
||||
// For SSR
|
||||
const url = Meteor.absoluteUrl(path);
|
||||
const networkInterface = createNetworkInterface({
|
||||
uri: url,
|
||||
opts: {
|
||||
credentials: 'same-origin',
|
||||
}
|
||||
});
|
||||
|
||||
networkInterface.use([{
|
||||
applyMiddleware(request, next) {
|
||||
|
||||
// login token created by meteorhacks:fast-render and caught during server-side rendering by rr:react-router-ssr
|
||||
const { cookieLoginToken } = config;
|
||||
// Meteor accounts-base login token stored in local storage, only exists client-side
|
||||
const localStorageLoginToken = Meteor.isClient && Accounts._storedLoginToken();
|
||||
|
||||
// on initial load, prefer to use the server cookie if existing
|
||||
let currentUserToken = cookieLoginToken || localStorageLoginToken;
|
||||
|
||||
// ...a login token has been passed to the config, however the "true" one is different ⚠️
|
||||
if (Meteor.isClient && cookieLoginToken && cookieLoginToken !== localStorageLoginToken) {
|
||||
// be sure to pass the right token to the request 🎉
|
||||
currentUserToken = localStorageLoginToken;
|
||||
}
|
||||
|
||||
if (!currentUserToken) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!request.options.headers) {
|
||||
request.options.headers = new Headers();
|
||||
}
|
||||
|
||||
request.options.headers.Authorization = currentUserToken;
|
||||
|
||||
next();
|
||||
},
|
||||
}]);
|
||||
|
||||
return networkInterface;
|
||||
};
|
||||
|
||||
export const meteorClientConfig = (networkInterfaceConfig) => {
|
||||
return {
|
||||
ssrMode: Meteor.isServer,
|
||||
networkInterface: createMeteorNetworkInterface(networkInterfaceConfig),
|
||||
queryDeduplication: true,
|
||||
|
||||
// Default to using Mongo _id, must use _id for queries.
|
||||
dataIdFromObject: (result) => {
|
||||
if (result._id && result.__typename) {
|
||||
const dataId = result.__typename + result._id;
|
||||
return dataId;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// end of main-client from apollostack/meteor-integration
|
||||
// --------
|
||||
|
||||
// export const client = new ApolloClient(meteorClientConfig());
|
|
@ -1,34 +0,0 @@
|
|||
import { GraphQLSchema } from 'meteor/nova:core';
|
||||
|
||||
import { makeExecutableSchema } from 'graphql-tools';
|
||||
|
||||
import { meteorClientConfig } from './client.js';
|
||||
|
||||
import { createApolloServer } from './server.js';
|
||||
import generateTypeDefs from './schema';
|
||||
|
||||
import OpticsAgent from 'optics-agent'
|
||||
|
||||
Meteor.startup(function () {
|
||||
const typeDefs = generateTypeDefs();
|
||||
|
||||
GraphQLSchema.finalSchema = typeDefs;
|
||||
|
||||
const schema = makeExecutableSchema({
|
||||
typeDefs,
|
||||
resolvers: GraphQLSchema.resolvers,
|
||||
});
|
||||
|
||||
if (process.env.OPTICS_API_KEY) {
|
||||
OpticsAgent.instrumentSchema(schema)
|
||||
}
|
||||
|
||||
// uncomment for debug
|
||||
// console.log('// --> starting graphql server');
|
||||
|
||||
createApolloServer({
|
||||
schema,
|
||||
});
|
||||
});
|
||||
|
||||
export { meteorClientConfig };
|
|
@ -1,20 +0,0 @@
|
|||
import { GraphQLSchema } from 'meteor/nova:core';
|
||||
|
||||
const generateTypeDefs = () => [`
|
||||
|
||||
scalar JSON
|
||||
scalar Date
|
||||
|
||||
${GraphQLSchema.getCollectionsSchemas()}
|
||||
${GraphQLSchema.getAdditionalSchemas()}
|
||||
|
||||
type Query {
|
||||
${GraphQLSchema.queries.join('\n')}
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
${GraphQLSchema.mutations.join('\n')}
|
||||
}
|
||||
`];
|
||||
|
||||
export default generateTypeDefs;
|
|
@ -1,138 +0,0 @@
|
|||
// note(oct. 28, 2016)
|
||||
// by-pass the meteor integration to use the features of apollo-client 0.5.x / graphql-server 0.4.x
|
||||
|
||||
// -------
|
||||
// start of main-client from apollostack/meteor-integration
|
||||
|
||||
import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
|
||||
import bodyParser from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import express from 'express';
|
||||
|
||||
import deepmerge from 'deepmerge';
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { WebApp } from 'meteor/webapp';
|
||||
import { check } from 'meteor/check';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
import { _ } from 'meteor/underscore';
|
||||
|
||||
import Users from 'meteor/nova:users';
|
||||
|
||||
import { GraphQLSchema } from 'meteor/nova:core';
|
||||
|
||||
import OpticsAgent from 'optics-agent'
|
||||
|
||||
|
||||
const defaultConfig = {
|
||||
path: '/graphql',
|
||||
maxAccountsCacheSizeInMB: 1,
|
||||
graphiql : Meteor.isDevelopment,
|
||||
graphiqlPath : '/graphiql',
|
||||
graphiqlOptions : {
|
||||
passHeader : "'Authorization': localStorage['Meteor.loginToken']"
|
||||
},
|
||||
configServer: (graphQLServer) => {},
|
||||
};
|
||||
|
||||
const defaultOptions = {
|
||||
formatError: e => ({
|
||||
message: e.message,
|
||||
locations: e.locations,
|
||||
path: e.path
|
||||
}),
|
||||
debug: Meteor.isDevelopment,
|
||||
};
|
||||
|
||||
export const createApolloServer = (givenOptions = {}, givenConfig = {}) => {
|
||||
|
||||
let graphiqlOptions = Object.assign({}, defaultConfig.graphiqlOptions, givenConfig.graphiqlOptions);
|
||||
let config = Object.assign({}, defaultConfig, givenConfig);
|
||||
config.graphiqlOptions = graphiqlOptions;
|
||||
|
||||
const graphQLServer = express();
|
||||
|
||||
config.configServer(graphQLServer)
|
||||
|
||||
// Load the cookie parsing middleware, used to grab login token
|
||||
graphQLServer.use(cookieParser());
|
||||
|
||||
// Use Optics middleware
|
||||
if (process.env.OPTICS_API_KEY) {
|
||||
graphQLServer.use(OpticsAgent.middleware());
|
||||
}
|
||||
|
||||
// GraphQL endpoint
|
||||
graphQLServer.use(config.path, bodyParser.json(), graphqlExpress(async (req) => {
|
||||
let options,
|
||||
user = null;
|
||||
|
||||
// console.log('Login token: ', req.cookies.meteor_login_token);
|
||||
|
||||
if (_.isFunction(givenOptions))
|
||||
options = givenOptions(req);
|
||||
else
|
||||
options = givenOptions;
|
||||
|
||||
// Merge in the defaults
|
||||
options = Object.assign({}, defaultOptions, options);
|
||||
|
||||
if (options.context) {
|
||||
// don't mutate the context provided in options
|
||||
options.context = Object.assign({}, options.context);
|
||||
} else {
|
||||
options.context = {};
|
||||
}
|
||||
|
||||
// Add Optics to GraphQL context object
|
||||
if (process.env.OPTICS_API_KEY) {
|
||||
options.context.opticsContext = OpticsAgent.context(req);
|
||||
}
|
||||
|
||||
options.context.getViewableFields = Users.getViewableFields;
|
||||
|
||||
// Get the token from the header
|
||||
if (req.headers.authorization) {
|
||||
const token = req.headers.authorization;
|
||||
check(token, String);
|
||||
const hashedToken = Accounts._hashLoginToken(token);
|
||||
|
||||
// Get the user from the database
|
||||
user = await Users.findOne(
|
||||
{"services.resume.loginTokens.hashedToken": hashedToken},
|
||||
// {fields: {
|
||||
// _id: 1,
|
||||
// 'services.resume.loginTokens.$': 1
|
||||
// }}
|
||||
);
|
||||
|
||||
if (user) {
|
||||
|
||||
const expiresAt = Accounts._tokenExpiration(user.services.resume.loginTokens[0].when);
|
||||
const isExpired = expiresAt < new Date();
|
||||
|
||||
if (!isExpired) {
|
||||
|
||||
options.context.userId = user._id;
|
||||
options.context.currentUser = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
options.context = deepmerge(options.context, GraphQLSchema.context);
|
||||
|
||||
return options;
|
||||
|
||||
}));
|
||||
|
||||
// Start GraphiQL if enabled
|
||||
if (config.graphiql) {
|
||||
graphQLServer.use(config.graphiqlPath, graphiqlExpress(_.extend(config.graphiqlOptions, {endpointURL : config.path})));
|
||||
}
|
||||
|
||||
// This binds the specified paths to the Express server running Apollo + GraphiQL
|
||||
WebApp.connectHandlers.use(Meteor.bindEnvironment(graphQLServer));
|
||||
};
|
||||
|
||||
// end of main-client from apollostack/meteor-integration
|
||||
// -------
|
|
@ -1,24 +0,0 @@
|
|||
Package.describe({
|
||||
name: "nova:apollo",
|
||||
summary: "Nova Apollo Server package",
|
||||
version: "1.0.0",
|
||||
git: "https://github.com/TelescopeJS/Telescope.git"
|
||||
});
|
||||
|
||||
Package.onUse(function (api) {
|
||||
|
||||
api.versionsFrom(['METEOR@1.0']);
|
||||
|
||||
api.use([
|
||||
|
||||
// Nova packages
|
||||
|
||||
'nova:core@1.0.0',
|
||||
'nova:users@1.0.0',
|
||||
|
||||
]);
|
||||
|
||||
api.mainModule("lib/client.js", "client");
|
||||
api.mainModule("lib/export.js", "server"); // client.js inside of export.js for ssr purpose
|
||||
|
||||
});
|
Loading…
Add table
Reference in a new issue