Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types missing when using two nexus-plugin-prisma instances. #1036

Open
fullStackDataSolutions opened this issue Jan 26, 2021 · 0 comments
Open

Comments

@fullStackDataSolutions
Copy link

fullStackDataSolutions commented Jan 26, 2021

I'm connecting to two different DBs and have created two different makeSchema() which I use mergeSchema to combine.

This all works fine, however I can't build as Typescript is not loading the types for the second instance of schema. Here's an example of one of the index files::

import { nexusPrisma } from 'nexus-plugin-prisma'
import { makeSchema, connectionPlugin, declarativeWrappingPlugin } from 'nexus'
import {
    transformSchema,
    FilterObjectFields
} from 'graphql-tools'
import * as path from 'path'

import Query from './Query'
import Mutation from './Mutation'
import * as enums from './enum'
import * as types from './types'


import { blacklistedTypeFields } from '../../utils/blacklistedTypeFields'
import { nullGuardPlugin } from '../plugins/nullabilityGuard'

const DEBUGGING_CURSOR = false

// Part of Relay connection implementation
let fn = DEBUGGING_CURSOR ? (i: string) => i : undefined

const schema = makeSchema({
    types: [
        types, Query, enums, Mutation
        ],
       contextType: { module: path.join(__dirname, '../../utils/types'), export: "Context"},
    plugins: [
        declarativeWrappingPlugin(),
        connectionPlugin({
            encodeCursor: fn,
            decodeCursor: fn
        }),
        nullGuardPlugin,
        nexusPrisma({
            experimentalCRUD: true,
            prismaClient: (ctx) => ctx.users,
            computedInputs: {
                login: (data) => data.ctx.login 
            },
            inputs: { prismaClient: path.join(__dirname, '../../generated/prisma/users/client') },
            outputs: {​​​​​​​​ typegen: path.join(__dirname, '../../generated/nexus/users/index.ts') }​​​​​​​​,
        })
    ],
    outputs: {
        schema: path.join(__dirname, '../../generated/nexus/users/schema.graphql'),
        typegen: path.join(__dirname, '../../generated/nexus/users/nexus.ts')
    }
})

// Transform schema to filter out certain fields from types for security purposes
const transformedSchema = transformSchema(schema, [
    new FilterObjectFields(
        (_typeName, fieldName) =>
            !blacklistedTypeFields.includes(fieldName as string)
    )
])

export { transformedSchema as default }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant