Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { GraphQLServer } from 'graphql-yoga'
import { prisma } from './generated/prisma-client'
import resolvers from './resolvers'
import { PubSub } from 'graphql-subscriptions'
import { makePrismaSchema } from 'nexus-prisma'
import datamodelInfo from './generated/nexus-prisma'
import * as path from 'path'
import { IncomingMessage } from 'http'
const pubsub = new PubSub()
const schema = makePrismaSchema({
// Provide all the GraphQL types we've implemented
types: resolvers,
// Configure the interface to Prisma
prisma: {
datamodelInfo,
client: prisma
},
// Specify where Nexus should put the generated files
outputs: {
schema: path.join(__dirname, './generated/schema.graphql'),
typegen: path.join(__dirname, './generated/nexus.ts')
},
// Configure nullability of input arguments: All arguments are non-nullable by default
const Query = prismaObjectType({
name: 'Query',
definition(t) {
t.prismaFields(['*'])
},
})
const Mutation = prismaObjectType({
name: 'Mutation',
definition(t) {
t.prismaFields(['*'])
},
})
const schema = makePrismaSchema({
// Provide all the GraphQL types we've implemented
types: [Query, Mutation, User, Post],
// Configure the interface to Prisma
prisma: {
datamodelInfo,
client: prisma,
},
// Specify where Nexus should put the generated files
outputs: {
schema: path.join(__dirname, './generated/schema.graphql'),
typegen: path.join(__dirname, './generated/nexus.ts'),
},
// Configure nullability of input arguments: All arguments are non-nullable by default
import { GraphQLSchema } from 'graphql';
import datamodelInfo from './generated/nexus-prisma';
import { permissions } from './permissions';
import * as allTypes from './resolvers';
import { Prisma, prisma } from './generated/prisma-client';
import { Ctx } from './types';
const prismaInstance = (): Prisma =>
new Prisma({
endpoint: process.env.PRISMA_ENDPOINT,
debug: process.env.NODE_ENV !== 'production', // log all GraphQL queries & mutations sent to the Prisma API
secret: process.env.PRISMA_SECRET, // only needed if specified in `database/prisma.yml` (value set in `.env`)
});
const schema: GraphQLSchema = applyMiddleware(
makePrismaSchema({
// Provide all the GraphQL types we've implemented
types: allTypes,
// Configure the interface to Prisma
prisma: {
datamodelInfo,
client: prisma,
},
// Specify where Nexus should put the generated files
outputs: {
schema: path.resolve('./src/generated/schema.graphql'),
typegen: path.resolve('./src/generated/nexus.ts'),
},
// Configure nullability of input arguments: All arguments are non-nullable by default
import * as path from 'path';
import { GraphQLServer } from 'graphql-yoga';
import { makePrismaSchema } from 'nexus-prisma';
import { prisma } from './generated/prisma-client';
import datamodelInfo from './generated/nexus-prisma';
import * as types from './resolvers';
const schema = makePrismaSchema({
types,
prisma: {
datamodelInfo,
client: prisma,
},
outputs: {
schema: path.join(__dirname, './generated/schema.graphql'),
typegen: path.join(__dirname, './generated/nexus.ts'),
},
});
const server = new GraphQLServer({
schema,
context: { prisma },
import * as types from './resolvers'
const playground = !!Number(process.env.IS_PLAYGROUND_ENABLED || '0')
const tracing = !!Number(process.env.IS_TRACING_ENABLED || '0')
const app = express()
app.use(cors())
app.get('/', (_req, res) => {
return res.json('ok')
})
const server = new ApolloServer({
schema: makePrismaSchema({
types,
prisma: {
client: prisma,
datamodelInfo,
},
outputs: {
schema: path.resolve('./src/generated', 'schema.graphql'),
typegen: path.resolve('./src/generated', 'nexus.ts'),
},
}),
introspection: playground,
playground,
tracing,
})
server.applyMiddleware({
import { makePrismaSchema } from 'nexus-prisma'
import * as path from 'path'
import datamodelInfo from './generated/nexus-prisma'
import { prisma } from './generated/prisma-client'
import * as allTypes from './resolvers'
/**
* Finally, we construct our schema (whose starting query type is the query
* type we defined above) and export it.
*/
export const schema = makePrismaSchema({
types: allTypes,
prisma: {
datamodelInfo,
client: prisma,
},
outputs: {
schema: path.join(__dirname, './generated/schema.graphql'),
typegen: path.join(__dirname, './generated/nexus.ts'),
},
nonNullDefaults: {
input: true,
output: true,
},
ctx.viewerId ? ctx.prisma.user({ id: ctx.viewerId }) : null
});
}
});
const outputs = process.env.GENERATE
? {
schema: path.join(__dirname, "../schema.generated.graphql"),
typegen: path.join(__dirname, "../nexus-schema-types.generated.ts")
}
: {
schema: false,
typegen: false
};
const schema = makePrismaSchema({
types: [Query, User],
prisma: {
datamodelInfo,
client: prisma
},
outputs,
typegenAutoConfig: {
sources: [
{
source: path.join(__dirname, "../../types/graphql.ts"),
alias: "types"
}
],
contextType: "types.Context"
}
});
async server() {
const app = express()
const { types, context, expressMiddleware } = importArtifacts(
config.resolversPath,
config.contextPath,
config.expressPath,
)
const makeSchemaOptions = makeSchemaDefaults(
config,
types,
info.prismaClientDir,
)
const schema = config.prisma
? makePrismaSchema({
...makeSchemaOptions,
prisma: config.prisma,
})
: makeSchema(makeSchemaOptions)
const server = new ApolloServer({
schema,
context,
})
if (expressMiddleware) {
await expressMiddleware(app)
}
server.applyMiddleware({ app, path: '/' })
return app