How to use the nexus.makeSchema function in nexus

To help you get started, we’ve selected a few nexus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yusinto / universal-hot-reload / examples / ts / src / server.ts View on Github external
import { queryType, stringArg, makeSchema } from 'nexus'
import path from 'path'

const PORT = 4000
const GENERATED_OUTPUT_PATH = `${path.resolve('.')}/__generated/`

const Query = queryType({
  definition(t) {
    t.string('hello', {
      args: { name: stringArg({ nullable: true }) },
      resolve: (parent, { name }) => `Hello ${name || 'world'}`,
    })
  },
})

const schema = makeSchema({
  types: [Query],
  outputs: {
    schema: `${GENERATED_OUTPUT_PATH}schema.graphql`,
    typegen: `${GENERATED_OUTPUT_PATH}typings.ts`,
  },
})

const server = new ApolloServer({
  schema,
})
server.listen({ port: PORT }, () => console.log(`🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`))

// @ts-ignore
export default server.httpServer
github este / este / packages / api / index.ts View on Github external
import { getUser } from './getUser';
import { createModels } from './models';

const { PRISMA_ENDPOINT, PRISMA_SECRET, API_SECRET } = process.env;
if (!PRISMA_ENDPOINT || !PRISMA_SECRET || !API_SECRET)
  throw Error(`Did you run 'yarn env dev'?`);

// Nullability
// https://blog.apollographql.com/designing-graphql-mutations-e09de826ed97
// https://blog.apollographql.com/using-nullability-in-graphql-2254f84c4ed7
// Remember
//  For input arguments and fields, adding non-null is a breaking change.
//  For output fields, removing non-null from a field is a breaking change.
//  By id queries like web(id: ID!): Web! returns always non nullable value,
//  because errors are passed as permissions exists or isWebCreatorOrAdmin etc.
const schema = makeSchema({
  types: schemaTypes,
  // All inputs are non nullable.
  // Remember, after release, every new input must be nullable.
  // Note payloads and errors needs nonNullDefaults: { output: false }.
  nonNullDefaults: { input: true },
  outputs: {
    schema: path.join(__dirname, './schema.graphql'),
    typegen: path.join(__dirname, './typegen.ts'),
  },
  typegenAutoConfig: {
    // debug: true,
    sources: [{ source: path.join(__dirname, './types.ts'), alias: 'types' }],
    contextType: 'types.Context',
  },
  // backingTypeMap: {
  //   EmailAddress: 'string',
github prisma / prisma-examples / javascript / graphql-auth / src / index.js View on Github external
const { GraphQLServer } = require('graphql-yoga')
const { nexusPrismaPlugin } = require('nexus-prisma')
const { makeSchema } = require('nexus')
const { Photon } = require('@prisma/photon')
const { permissions } = require('./permissions')
const types = require('./types')

const photon = new Photon()

new GraphQLServer({
  schema: makeSchema({
    types,
    plugins: [nexusPrismaPlugin()],
  }),
  middlewares: [permissions],
  context: request => {
    return {
      ...request,
      photon,
    }
  },
}).start(() =>
  console.log(
    `🚀 Server ready at: http://localhost:4000\n⭐️ See sample queries: http://pris.ly/e/js/graphql-auth#5-using-the-graphql-api`,
  ),
)
github tonyfromundefined / serverless-graphql-workshop / starters / server / src / app.ts View on Github external
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: makeSchema({
    types,
    outputs: {
      schema: path.resolve('./src/generated', 'schema.graphql'),
      typegen: path.resolve('./src/generated', 'nexus.ts'),
    },
  }),
  introspection: playground,
  playground,
  tracing,
})

server.applyMiddleware({
  app,
})

export default app
github prisma / prisma-examples / typescript / graphql-auth / src / index.ts View on Github external
import { nexusPrismaPlugin } from 'nexus-prisma'
import { Photon } from '@generated/photon'
import { makeSchema } from 'nexus'
import { GraphQLServer } from 'graphql-yoga'
import { join } from 'path'
import { permissions } from './permissions'
import * as allTypes from './resolvers'

const photon = new Photon()

const nexusPrismaTypes = nexusPrismaPlugin({
  types: allTypes,
})
const schema = makeSchema({
  types: [allTypes, nexusPrismaTypes],
  outputs: {
    schema: join(__dirname, '/schema.graphql'),
  },
  typegenAutoConfig: {
    sources: [
      {
        source: '@generated/photon',
        alias: 'photon',
      },
      {
        source: join(__dirname, 'types.ts'),
        alias: 'ctx',
      },
    ],
    contextType: 'ctx.Context',
github tonyfromundefined / codelab-graphql / 2_nexus / src / app.ts View on Github external
function createApolloServer() {
  const schema = makeSchema({
    types: {
      scalars: {},
      resolvers,
    },
    outputs: {
      schema: path.resolve(__generated, 'schema.graphql'),
      typegen: path.resolve(__generated, 'nexus.ts'),
    },
    typegenAutoConfig: {
      sources: createTypegenConfigSources(),
      contextType: 'Context',
    },
  })

  const server = new ApolloServer({
    schema,
github arkhn / pyrog / server-v2 / src / schema.ts View on Github external
import { nexusPrismaPlugin } from 'nexus-prisma'
import { makeSchema } from 'nexus'

import * as types from 'types'

export const schema = makeSchema({
  types,
  plugins: [nexusPrismaPlugin()],
  outputs: {
    schema: __dirname + '/generated/schema.graphql',
    typegen: __dirname + '/generated/nexus.ts',
  },
  typegenAutoConfig: {
    sources: [
      {
        source: '@prisma/photon',
        alias: 'photon',
      },
      {
        source: require.resolve('./context'),
        alias: 'Context',
      },