How to use the nexus.queryType 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 prisma-labs / nexus-prisma / tests / __app / main.ts View on Github external
import { objectType, queryType, mutationType } from 'nexus'

export const Query = queryType({
  definition(t) {
    // ASSERT findOne & findMany
    t.crud.user()
    t.crud.users()
  },
})

export const Mutation = mutationType({
  definition: t => {
    t.crud.createOnePost()
    t.crud.updateManyPost()
  },
})

export const User = objectType({
  name: 'User',
github prisma / photonjs / examples / typescript / graphql-apollo-server / src / index.ts View on Github external
})

const Post = objectType({
  name: 'Post',
  definition(t) {
    t.model.id()
    // t.model.createdAt()
    // t.model.updatedAt()
    t.model.title()
    t.model.content()
    t.model.published()
    t.model.author({ type: 'User' })
  },
})

const Query = queryType({
  definition(t) {
    t.field('hello', {
      type: 'String',
      resolve: () => {
        return `world`
      },
    })

    t.list.field('feed', {
      type: 'Post',
      resolve: (parent, args, ctx) => {
        return ctx.photon.posts.findMany({
          where: { published: true },
        })
      },
    })
github este / este / packages / api / schema / index.ts View on Github external
// NonPositiveInt,
  // PositiveInt,
  // NonNegativeInt,
  // NegativeInt,
  // NonPositiveFloat,
  // PositiveFloat,
  // NonNegativeFloat,
  // NegativeFloat,
} from '@okgrow/graphql-scalars';

export * from './errors';
export * from './user';
export * from './web';

// https://github.com/prisma/nexus/issues/132
export const Query = queryType({
  nonNullDefaults: { input: true },
  definition() {},
});

// And t.dateTime() is now available (with types) because of `asNexusMethod`.
export const GQLDateTime = asNexusMethod(DateTime, 'dateTime');
export const GQLJSON = asNexusMethod(GraphQLJSON, 'json');

// Do not use string scalars until Relay will support type mapping.
// https://github.com/facebook/relay/issues/2718
// export const GQLEmailAddress = asNexusMethod(EmailAddress, 'emailAddress');
// export const GQLURL = asNexusMethod(URL, 'URL');
// export const GQLMax140Chars = asNexusMethod(
//   new RegularExpression('Max140Chars', /[\s\S]{0,140}/),
//   'max140Chars',
// );
github prisma-labs / nexus-prisma / examples / blog / src / schema / Query.ts View on Github external
import { queryType, idArg, intArg, stringArg } from 'nexus'

export const Query = queryType({
  definition(t) {
    t.crud.blogs({
      pagination: false,
    })
    t.crud.users({ filtering: true, alias: 'people' })
    t.crud.posts({ type: 'CustomPost', ordering: true, filtering: true })

    //
    // Examples showing custom resolvers
    //

    t.field('blog', {
      type: 'Blog',
      args: {
        id: intArg({ required: true }),
      },
github guildspeak / guildspeak-backend / server / src / resolvers / query.ts View on Github external
import { getUserId, isUserInChannel } from '../utils'
import { idArg, queryType } from 'nexus'
import { Context } from '../types'

export const Query = queryType({
  definition(t) {
    t.list.field('guilds', {
      type: 'Guild',
      resolve: async (parent, args, ctx: Context) => {
        const id = await getUserId(ctx)
        return await ctx.prisma.guilds({ where: { users_some: { id } } })
      }
    })

    t.field('guild', {
      type: 'Guild',
      args: { id: idArg() },
      resolve: async (parent, { id }, ctx: Context) => {
        return await ctx.prisma.guild({ id })
      }
    })
github nodkz / conf-talks / articles / graphql / schema-build-ways / nexus.ts View on Github external
definition(t) {
    t.string('title');
    t.string('text', { nullable: true });
    t.int('authorId', { description: 'Record id from Author table' });
    t.field('author', {
      nullable: true,
      type: 'Author',
      resolve: source => {
        const { authorId } = source;
        return authors.find(o => o.id === authorId) as any;
      },
    });
  },
});

const Query = queryType({
  definition(t) {
    t.list.field('articles', {
      nullable: true,
      type: Article,
      args: {
        limit: intArg({ default: 3, required: true })
      },
      resolve: (_, args) => {
        const { limit } = args;
        return articles.slice(0, limit);
      },
    });
    t.list.field('authors', {
      nullable: true,
      type: Author,
      resolve: () => authors,
github tonyfromundefined / codelab-graphql / 2_nexus / src / resolvers / Query.ts View on Github external
import { queryType } from 'nexus'

export const Query = queryType({
  definition(t) {
    t.string('ping', {
      resolve() {
        return 'pong'
      },
    })
  },
})
github prisma / prisma-examples / javascript / graphql-auth / src / types / Query.js View on Github external
const { idArg, queryType, stringArg } = require('nexus')
const { getUserId } = require('../utils')

const Query = queryType({
  definition(t) {
    t.field('me', {
      type: 'User',
      nullable: true,
      resolve: (parent, args, ctx) => {
        const userId = getUserId(ctx)
        return ctx.photon.users.findOne({
          where: {
            id: userId,
          },
        })
      },
    })

    t.list.field('feed', {
      type: 'Post',
github tonyfromundefined / serverless-graphql-workshop / starters / server / src / resolvers / Query.ts View on Github external
import { queryType } from 'nexus'

export const Query = queryType({
  definition(t) {
    t.string('stage', {
      resolve: (_parent, _args, _context) => {
        return process.env.STAGE as string
      },
    })
  },
})
github diego3g / graphql-nexus-example / src / resolvers / channels.ts View on Github external
import { queryType } from 'nexus';
import { prismaObjectType } from 'nexus-prisma';

import { Context } from '../types';

export const Channel = prismaObjectType({
  name: 'Channel',
  definition(t) {
    t.prismaFields(['*']);
  },
});

export const Query = queryType({
  definition(t) {
    t.list.field('testChannels', {
      type: 'Channel',
      resolve: (parent, args, ctx) => ctx.prisma.channels(),
    });
  },
});