Skip to content

Commit

Permalink
upgrade to nexus 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedElywa committed Dec 17, 2020
1 parent 4ac5cae commit 84dd21a
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 63 deletions.
2 changes: 1 addition & 1 deletion packages/create/examples/apollo-nexus-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dev": "ts-node-dev --no-notify --respawn --transpile-only src/server"
},
"dependencies": {
"@nexus/schema": "0.x",
"nexus": "1.x",
"@prisma/client": "2.x",
"@paljs/nexus": "2.9.1",
"apollo-server": "2.x",
Expand Down
14 changes: 5 additions & 9 deletions packages/create/examples/apollo-nexus-schema/src/nexusSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeSchema } from '@nexus/schema'
import { makeSchema } from 'nexus'
import * as types from './graphql'
import { paljs } from '@paljs/nexus'
import { join } from 'path'

export const schema = makeSchema({
types,
Expand All @@ -9,13 +10,8 @@ export const schema = makeSchema({
schema: __dirname + '/generated/schema.graphql',
typegen: __dirname + '/generated/nexus.ts',
},
typegenAutoConfig: {
sources: [
{
source: require.resolve('./context'),
alias: 'Context',
},
],
contextType: 'Context.Context',
contextType: {
module: join(__dirname, 'context.ts'),
export: 'Context',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dev": "ts-node-dev --no-notify --respawn --transpile-only src/server"
},
"dependencies": {
"@nexus/schema": "0.x",
"nexus": "1.x",
"@paljs/nexus": "2.9.1",
"@prisma/client": "2.x",
"apollo-server": "2.x",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType, stringArg } from '@nexus/schema'
import { extendType, nonNull, objectType, stringArg } from 'nexus'
import { compare, hash } from 'bcryptjs'
import { sign } from 'jsonwebtoken'
import { APP_SECRET } from '../utils'
Expand All @@ -14,9 +14,8 @@ export const AuthPayload = objectType({
export const AuthQueries = extendType({
type: 'Query',
definition(t) {
t.field('me', {
t.nullable.field('me', {
type: 'User',
nullable: true,
resolve: async (_, __, { prisma, select, userId }) => {
if (!userId) return null
return prisma.user.findUnique({
Expand All @@ -37,8 +36,8 @@ export const AuthMutations = extendType({
type: 'AuthPayload',
args: {
name: stringArg(),
email: stringArg({ nullable: false }),
password: stringArg({ nullable: false }),
email: nonNull('String'),
password: nonNull('String'),
},
resolve: async (_parent, { name, email, password }, ctx) => {
const hashedPassword = await hash(password, 10)
Expand All @@ -55,12 +54,11 @@ export const AuthMutations = extendType({
}
},
})
t.field('login', {
t.nullable.field('login', {
type: 'AuthPayload',
nullable: true,
args: {
email: stringArg({ nullable: false }),
password: stringArg({ nullable: false }),
email: nonNull('String'),
password: nonNull('String'),
},
resolve: async (_parent, { email, password }, ctx) => {
const user = await ctx.prisma.user.findUnique({
Expand All @@ -84,8 +82,8 @@ export const AuthMutations = extendType({
t.field('updatePassword', {
type: 'Boolean',
args: {
currentPassword: stringArg({ nullable: false }),
password: stringArg({ nullable: false }),
currentPassword: nonNull('String'),
password: nonNull('String'),
},
resolve: async (_, { currentPassword, password }, ctx) => {
if (currentPassword && password) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeSchema } from '@nexus/schema'
import { makeSchema } from 'nexus'
import * as types from './graphql'
import { paljs } from '@paljs/nexus'
import { join } from 'path'

export const schema = makeSchema({
types,
Expand All @@ -9,13 +10,8 @@ export const schema = makeSchema({
schema: __dirname + '/../schema.graphql',
typegen: __dirname + '/generated/nexus.ts',
},
typegenAutoConfig: {
sources: [
{
source: require.resolve('./context'),
alias: 'Context',
},
],
contextType: 'Context.Context',
contextType: {
module: join(__dirname, 'context.ts'),
export: 'Context',
},
})
2 changes: 1 addition & 1 deletion packages/create/examples/full-stack-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@apollo/client": "3.x",
"@apollo/react-ssr": "4.x",
"@nexus/schema": "0.x",
"nexus": "1.x",
"@paljs/nexus": "2.9.1",
"@paljs/admin": "2.9.0",
"@paljs/ui": "1.x",
Expand Down
20 changes: 9 additions & 11 deletions packages/create/examples/full-stack-nextjs/src/Api/graphql/Auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, stringArg } from '@nexus/schema'
import { extendType, nonNull, stringArg } from 'nexus'
import { compare, hash } from 'bcryptjs'
import { sign } from 'jsonwebtoken'
import { JWT_SECRET } from '../utils'
Expand All @@ -8,9 +8,8 @@ import { UserInputError } from 'apollo-server-micro'
export const AuthQueries = extendType({
type: 'Query',
definition(t) {
t.field('me', {
t.nullable.field('me', {
type: 'User',
nullable: true,
resolve: async (_, __, { prisma, select, userId }) => {
if (!userId) return null
return prisma.user.findUnique({
Expand All @@ -31,8 +30,8 @@ export const AuthMutations = extendType({
type: 'User',
args: {
name: stringArg(),
email: stringArg({ nullable: false }),
password: stringArg({ nullable: false }),
email: nonNull('String'),
password: nonNull('String'),
},
resolve: async (_parent, { name, email, password }, ctx) => {
const hashedPassword = await hash(password, 10)
Expand All @@ -56,12 +55,11 @@ export const AuthMutations = extendType({
return user
},
})
t.field('login', {
t.nullable.field('login', {
type: 'User',
nullable: true,
args: {
email: stringArg({ nullable: false }),
password: stringArg({ nullable: false }),
email: nonNull('String'),
password: nonNull('String'),
},
resolve: async (_parent, { email, password }, ctx) => {
const user = await ctx.prisma.user.findUnique({
Expand Down Expand Up @@ -108,8 +106,8 @@ export const AuthMutations = extendType({
t.field('updatePassword', {
type: 'Boolean',
args: {
currentPassword: stringArg({ nullable: false }),
password: stringArg({ nullable: false }),
currentPassword: nonNull('String'),
password: nonNull('String'),
},
resolve: async (_, { currentPassword, password }, ctx) => {
if (currentPassword && password) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeSchema } from '@nexus/schema'
import { makeSchema } from 'nexus'
import * as types from './graphql'
import { paljs } from '@paljs/nexus'
import { join } from 'path'
Expand All @@ -10,13 +10,8 @@ export const schema = makeSchema({
schema: join(process.cwd(), 'src', 'generated', 'schema.graphql'),
typegen: join(process.cwd(), 'nexus-typegen.ts'),
},
typegenAutoConfig: {
sources: [
{
source: require.resolve('./context'),
alias: 'Context',
},
],
contextType: 'Context.Context',
contextType: {
module: join(__dirname, 'context.ts'),
export: 'Context',
},
})
2 changes: 1 addition & 1 deletion packages/generator/src/nexus-prisma-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class GenerateNexusPrismaPlugin extends Generators {
? ', extendType'
: ''
}}`,
'@nexus/schema',
'nexus',
),
'\n',
];
Expand Down
5 changes: 1 addition & 4 deletions packages/generator/src/nexus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export class GenerateNexus extends Generators {
}
}

let fileContent = `${this.getImport(
'{ objectType }',
'@nexus/schema',
)}\n\n`;
let fileContent = `${this.getImport('{ objectType }', 'nexus')}\n\n`;

fileContent += `${!this.isJS ? 'export ' : ''}const ${
model.name
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/nexus/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function getCrud(
`{ ${
type === 'query' ? 'queryField' : 'mutationField'
}, arg${getImportArgs()} }`,
'@nexus/schema',
'nexus',
);
return crud[key]
.replace(/#{Model}/g, model)
Expand Down
2 changes: 1 addition & 1 deletion packages/nexus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"access": "public"
},
"devDependencies": {
"@nexus/schema": "0.19.2",
"nexus": "1.0.0",
"@prisma/client": "2.13.0",
"@types/lowdb": "1.0.9",
"typescript": "4.1.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/nexus/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
inputObjectType,
extendType,
nonNull,
} from '@nexus/schema';
} from 'nexus';
import low from 'lowdb';
import FileSync from 'lowdb/adapters/FileSync';
import { NexusAcceptedTypeDef } from '@nexus/schema/dist/builder';
import { NexusAcceptedTypeDef } from 'nexus/dist/builder';
import { Schema } from '@paljs/types';
import { existsSync } from 'fs';
import { join } from 'path';
Expand Down
4 changes: 2 additions & 2 deletions packages/nexus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
objectType,
plugin,
scalarType,
} from '@nexus/schema';
import { NexusAcceptedTypeDef } from '@nexus/schema/dist/builder';
} from 'nexus';
import { NexusAcceptedTypeDef } from 'nexus/dist/builder';
import { dmmf } from '@prisma/client';
import { DMMF } from '@prisma/client/runtime';
import { adminNexusSchemaSettings } from './admin';
Expand Down

0 comments on commit 84dd21a

Please sign in to comment.