Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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',
})
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 },
})
},
})
// 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',
// );
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 }),
},
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 })
}
})
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,
import { queryType } from 'nexus'
export const Query = queryType({
definition(t) {
t.string('ping', {
resolve() {
return 'pong'
},
})
},
})
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',
import { queryType } from 'nexus'
export const Query = queryType({
definition(t) {
t.string('stage', {
resolve: (_parent, _args, _context) => {
return process.env.STAGE as string
},
})
},
})
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(),
});
},
});