Skip to content

Commit

Permalink
refactor: use new nexus package
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Dec 14, 2020
1 parent a052ae2 commit 913ffa1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 29 deletions.
29 changes: 27 additions & 2 deletions api/graphql/Post.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import {
extendType,
intArg,
interfaceType,
nonNull,
objectType,
stringArg,
} from '@nexus/schema'
stringArg
} from 'nexus'

export const Media = interfaceType({
name: 'Media',
resolveType(source) {
return 'director' in source ? 'Movie' : 'Song'
},
definition(t) {
t.string('url')
},
})
export const Movie = objectType({
name: 'Movie',
definition(t) {
t.implements('Media')
t.string('director')
},
})
export const Song = objectType({
name: 'Song',
definition(t) {
t.implements('Media')
t.string('album')
},
})

export const Post = objectType({
name: 'Post',
Expand Down
14 changes: 4 additions & 10 deletions api/schema.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { makeSchema } from '@nexus/schema'
import { makeSchema } from 'nexus'
import { join } from 'path'
import * as types from './graphql'

export const schema = makeSchema({
types,
outputs: {
typegen: join(__dirname, '../node_modules/@types/nexus-typegen/index.d.ts'),
schema: join(__dirname, '../schema.graphql'),
},
typegenAutoConfig: {
sources: [
{
source: join(__dirname, './context.ts'),
alias: 'ContextModule',
},
],
contextType: 'ContextModule.Context',
contextType: {
module: join(__dirname, './context.ts'),
export: 'Context'
},
})
30 changes: 14 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"license": "MIT",
"keywords": [],
"dependencies": {
"@nexus/schema": "^0.19.2",
"@prisma/client": "^2.12.1",
"apollo-server": "^2.19.0",
"graphql": "^15.4.0",
"nexus": "^1.0.0",
"nexus-plugin-prisma": "0.10.0"
},
"devDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
### Do not make changes to this file directly


interface Media {
url: String
}

type Movie implements Media {
director: String
url: String
}

type Mutation {
createDraft(body: String!, title: String!): Post
publish(draftId: Int!): Post
Expand All @@ -18,3 +27,8 @@ type Query {
drafts: [Post]
posts: [Post]
}

type Song implements Media {
album: String
url: String
}

0 comments on commit 913ffa1

Please sign in to comment.