Skip to content

Commit

Permalink
fix build step for graphql-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Apr 29, 2022
1 parent 4f4d6d0 commit c57bdfa
Show file tree
Hide file tree
Showing 8 changed files with 887 additions and 254 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@lerna-lite/cli": "^1.0.5",
"@mdx-js/react": "^1.6.22",
"@storybook/addon-actions": "^6.4.5",
"@storybook/addon-docs": "^6.4.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"test": "echo \"Error: run tests from root\" && exit 1",
"build:tsup": "tsup",
"build:types": "tsc --emitDeclarationOnly --declaration --project tsconfig.build.json ",
"build": "yarn run build:tsup"
"build": "yarn run build:tsup --external graphql --external graphql-tag"
},
"bugs": {
"url": "https://github.com/VulcanJS/vulcan-npm/issues"
Expand Down
9 changes: 7 additions & 2 deletions packages/graphql/server/parseAllModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
*
* Previously was the main GraphQL object
*/
import { disableFragmentWarnings } from "graphql-tag";

// Won't work (05/2022) because we treat graphql-tag as an external during build due to
// https://github.com/evanw/esbuild/issues/1921,
// Which in turns makes it a CJS import
//import { disableFragmentWarnings } from "graphql-tag";
import gql from "graphql-tag";

import parseModel from "./parseModel";
import { VulcanGraphqlModel } from "../typings";
Expand All @@ -19,7 +24,7 @@ import {
MutationTypeDefinition,
} from "./typings";

disableFragmentWarnings();
gql.disableFragmentWarnings();

// TODO: parse all models and return the whole schema
export const parseAllModels = (
Expand Down
9 changes: 7 additions & 2 deletions packages/react-ui/components/form/tests/formFragments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ const makeModel = (schema) =>
},
});

import { disableFragmentWarnings } from "graphql-tag";
// Won't work (05/2022) because we treat graphql-tag as an external during build due to
// https://github.com/evanw/esbuild/issues/1921,
// Which in turns makes it a CJS import
//import { disableFragmentWarnings } from "graphql-tag/";
import gql from "graphql-tag";

beforeEach(() => {
// @see https://github.com/apollographql/graphql-tag#warnings
// Let you define the same fragment twice in tests
disableFragmentWarnings();
gql.disableFragmentWarnings();
});
describe("vulcan:form/formFragments", function () {
test("generate valid query and mutation fragment", () => {
Expand Down
18 changes: 9 additions & 9 deletions starters/next/.vn/scripts/js-generated/seed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function closeDbConnection() {
import mongoose2 from "mongoose";

// src/lib/api/seed.ts
import { createMutator, getModelConnector } from "@vulcanjs/graphql/server";
import { createMutator } from "@vulcanjs/crud/server";

// src/models/user.server.ts
import merge from "lodash/merge.js";
Expand Down Expand Up @@ -245,7 +245,7 @@ async function findUserByCredentials({
email,
password
}) {
const user = await UserConnector.findOne({ email });
const user = await UserMongooseModel.findOne({ email });
if (!user) {
return null;
}
Expand Down Expand Up @@ -353,7 +353,8 @@ var modelDef2 = mergeModelDefinitionServer(modelDef, {
});
var User2 = createGraphqlModelServer(modelDef2);
var UserConnector = createMongooseConnector(User2);
User2.graphql.connector = UserConnector;
User2.crud.connector = UserConnector;
var UserMongooseModel = UserConnector.getRawCollection();

// src/lib/api/seed.ts
var seed = async (context) => {
Expand All @@ -362,9 +363,8 @@ var seed = async (context) => {
console.log("Using demo database, skip seeding");
return;
}
const UserConnector2 = getModelConnector(context, User2);
const seedAdminUser = async () => {
const count = await UserConnector2.count({ isAdmin: true });
const count = await UserMongooseModel.count({ isAdmin: true });
if (count === 0) {
console.log("No admin user found, seeding admin");
if (!process.env.ADMIN_EMAIL) {
Expand Down Expand Up @@ -486,7 +486,7 @@ var schema4 = merge2({}, schema3, {
arguments: "someArgument: String, anotherArgument: Int",
description: "A resolved field",
resolver: async (document, args, context, info) => {
const tenUsers = await UserConnector.find({}, { limit: 10 });
const tenUsers = await UserMongooseModel.find({}, null, { limit: 10 });
const filtered = tenUsers.filter((u) => {
var _a;
return (_a = u.email) == null ? void 0 : _a.match(document.demoCustomResolverField);
Expand All @@ -504,7 +504,7 @@ var modelDef4 = merge2({}, modelDef3, {
});
var SampleModel2 = createGraphqlModelServer2(modelDef4);
var SampleModelConnector = createMongooseConnector2(SampleModel2);
SampleModel2.graphql.connector = SampleModelConnector;
SampleModel2.crud.connector = SampleModelConnector;

// src/models/index.server.ts
import { addDefaultMongoConnector } from "@vulcanjs/mongo-apollo";
Expand All @@ -524,8 +524,8 @@ async function runSeed() {
try {
await connectToAppDb();
debugMongo("Connected to db, seeding admin and restaurants");
const contextBase2 = await createContextBase();
await seed_default(contextBase2);
const contextBase = await createContextBase();
await seed_default(contextBase);
const seedRestaurants = async () => {
const db = mongoose2.connection;
const count = await db.collection("restaurants").countDocuments();
Expand Down
2 changes: 1 addition & 1 deletion starters/next/.vn/scripts/js-generated/seed.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions starters/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"auto-changelog": "auto-changelog -u",
"build-storybook": "build-storybook",
"build:docker": "docker build -f ./.vn/docker/vn.production.dockerfile -t vulcan-next .",
"build:scripts": "tsup-node",
"build:scripts": "tsup-node --external graphql --external graphql-tag",
"build:static": "# Next Export is not compatible with i18n, this feature is now deactivated in Vulcan Next. See https://github.com/VulcanJS/vulcan-next/issues/98 #next build && next export",
"build:storybook": "rm -Rf storybook-static && build-storybook -s ./public # TODO: we shouldn't need to remove, but Storybook 6.1 has a small bug and can't remove existing build automatically",
"build:test:docker": "docker build -f ./.vn/docker/cypress.dockerfile -t vulcan-next-test .",
Expand Down Expand Up @@ -55,7 +55,7 @@
"start": "next start",
"storybook": "start-storybook -p 6006 -s ./public",
"test:docker": "docker run --env-file .env.development -it vns-test:latest",
"test:e2e": "cross-env NODE_ENV=test npm run build && start-server-and-test start:test http://localhost:3000 cypress:run",
"test:e2e": "cross-env NODE_ENV=test rm -Rf .next && npm run build && start-server-and-test start:test http://localhost:3000 cypress:run",
"test:unit": "jest",
"test:vn": "jest --config=./.vn/jest.config.vn.js --testPathPattern=tests/vn # run tests for Vulcan Next itself, eg scripts (long) ",
"test": "npm run test:unit && npm run test:e2e",
Expand Down
Loading

0 comments on commit c57bdfa

Please sign in to comment.