Skip to content

Commit

Permalink
start rewrite the full schema generation code, last step
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Oct 12, 2020
1 parent 323eb9f commit 0b5e84d
Show file tree
Hide file tree
Showing 14 changed files with 2,432 additions and 792 deletions.
6 changes: 5 additions & 1 deletion packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"dependencies": {
"@vulcanjs/model": "^0.0.6",
"@vulcanjs/schema": "^0.0.6",
"@vulcanjs/utils": "^0.0.6"
"@vulcanjs/utils": "^0.0.6",
"apollo-server": "^2.18.2",
"graphql-date": "^1.0.3",
"graphql-tools": "^6.2.4",
"graphql-type-json": "^0.3.2"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const isAdmin = function (user: User) {
* @param {Object} field - The full document of the collection
* @returns {Boolean} - true if the user can read the field, false if not
*/
const canReadField = function (
export const canReadField = function (
user: User,
field: Pick<VulcanFieldSchema, "canRead">,
document: Object
Expand Down
40 changes: 40 additions & 0 deletions packages/graphql/server/executableSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Finalize the graphql schema creation
*/

import { makeExecutableSchema } from "apollo-server";
import { mergeSchemas } from "graphql-tools";
import { REPL_MODE_SLOPPY } from "repl";
import { VulcanGraphqlModel } from "../typings";
import { generateGraqhqlSchema } from "./graphql";
import generateTypeDefs from "./typedefs";

// TODO: we probably don't need this anymore
// INstead, compute the schema for all models in graphql.ts
const initGraphQL = (models: Array<VulcanGraphqlModel>): void => {
// TODO: merge all models
const { resolvers, queries, mutations, typeDefs } = model
const typeDefs = generateTypeDefs({
additionalTypeDefs: GraphQLSchema.getAdditionalSchemas(),
modelTypeDefs: GraphQLSchema.getCollectionsSchemas(),
queries: GraphQLSchema.queries,
mutations: GraphQLSchema.mutations,
});

const executableSchema = makeExecutableSchema({
typeDefs,
resolvers: GraphQLSchema.resolvers,
schemaDirectives: GraphQLSchema.directives,
});
// only call mergeSchemas if we actually have stitchedSchemas
// const mergedSchema =
// GraphQLSchema.stitchedSchemas.length > 0
// ? mergeSchemas({
// schemas: [executableSchema, ...GraphQLSchema.stitchedSchemas],
// })
// : executableSchema;
//
return executableSchema,
};

export default initGraphQL;
Loading

0 comments on commit 0b5e84d

Please sign in to comment.