Hello,
I am trying to access the list method from the '@nexus/schema' package, but it is not resolving for me
import { list, objectType, queryType, mutationType, makeSchema, inputObjectType, stringArg } from '@nexus/schema';
Everything except for list seems to be exported fine for me.
Package.json
{
"name": "with-typescript",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"type-check": "tsc",
"migrate:save": "prisma migrate save --experimental",
"migrate:up": "prisma migrate up --experimental",
"migrate": "yarn migrate:save && yarn migrate:up",
"postinstall": "prisma generate",
"generate": "prisma generate"
},
"dependencies": {
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@nexus/schema": "0.14.0",
"graphql": "^15.3.0",
"@prisma/client": "^2.11.0",
"apollo-server-micro": "^2.19.0",
"axios": "^0.19.2",
"babel-plugin-styled-components": "^1.11.1",
"bcrypt": "^5.0.0",
"classnames": "^2.2.6",
"cookie": "^0.4.1",
"graphql-scalars": "^1.5.0",
"graphql-tag": "^2.11.0",
"isomorphic-unfetch": "^3.0.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"moment": "^2.29.1",
"next": "latest",
"next-images": "^1.4.1",
"next-urql": "^1.1.0",
"nexus": "^0.26.1",
"nexus-plugin-prisma": "^0.24.0",
"nookies": "^2.5.0",
"react": "^16.12.0",
"react-dates": "^21.8.0",
"react-dom": "^16.12.0",
"react-dropdown": "^1.9.0",
"react-icons": "^3.11.0",
"react-is": "^16.13.1",
"sass": "^1.26.10",
"styled-components": "^5.1.1",
"urql": "^1.10.0"
},
"devDependencies": {
"@prisma/cli": "^2.11.0",
"@types/node": "^12.12.21",
"@types/react": "^16.9.16",
"@types/react-dom": "^16.9.4",
"typescript": "3.7.3"
},
"license": "ISC"
}
Is anybody familiar with this problem?
Hi @15chrjef.
The docs for the new list / nonNull apis got merged before the official 0.19 release. If you install @nexus/[email protected] you'll be able to use these APIs. I anticipate the official 0.19 release will be out in the next day or two, just doing a bit of final API & docs cleanup.
Thank you @tgriesser! Also looking at some of the changes on 0.19.0, I see that the way to specify required fields has changed and no longer matches the syntax of
t.string('name', { required: true })
What is the preferred way to specify whether or not a field is now required?
You can import/add the declarativeWrappingPlugin() to the plugins array in makeSchema config and it will re-enable the previous behavior of nullable / list / required being defined on the object literal, but otherwise the preferred api is:
t.nonNull.string('name')
alias for
t.field('name', { type: nonNull('String') })
and for args
nonNull(stringArg()) // or arg({ type: nonNull('String') }))
The chaining API allows for simpler nested list types:
t.nonNull.list.nonNull.list.nonNull.string() // [[String!]!]!
or if you prefer:
nonNull(list(nonNull(list(nonNull('String')))))
@tgriesser Along similar lines, I am also seeing an error for the following
Error: The list/nullable/required object properies used in the 'Mutation.createOneuser' field's 'data' argument have been removed in favor of better chaining APIs
and the list() / nonNull() type wrapping functions. If you would like to incrementally migrate, or prefer the
existing API, it is now supported via the declarativeWrappingPlugin. Add this to your plugins array in your makeSchema config.
makeSchema({
plugins: [declarativePluginApi(), ...]
})
and other similar errors at other points of the schema
Error: The list/nullable/required object properies used in the 'Query.user' field's 'where' argument have been removed in favor of better chaining APIs
and the list() / nonNull() type wrapping functions. If you would like to incrementally migrate, or prefer the
existing API, it is now supported via the declarativeWrappingPlugin. Add this to your plugins array in your makeSchema config.
Error: The list/nullable/required object properies used in the 'user.guest_bookings' field's 'before' argument have been removed in favor of better chaining APIs
and the list() / nonNull() type wrapping functions. If you would like to incrementally migrate, or prefer the
existing API, it is now supported via the declarativeWrappingPlugin. Add this to your plugins array in your makeSchema config.
As an aside, When I try to import the declarativePluginAPI from @nexus/schema it does not seem to be found
Module '"../../node_modules/@nexus/schema/dist"' has no exported member 'declarativePluginApi'.
Is there a preferred way to do these crud methods now that is different from before?
My Schema
const User = objectType({
name: 'user',
definition(t) {
t.model.id();
t.model.first_name();
t.model.last_name();
t.model.email();
t.model.memberstack_id();
t.model.is_host();
t.model.created_at();
t.model.updated_at();
t.model.guest_bookings()
t.model.host_bookings()
t.model.houses()
}
});
const Mutation = mutationType({
definition(t) {
t.crud.createOneuser();
},
});
const Query = queryType({
definition(t) {
t.crud.user()
}
)}
The error message was incorrect, should be declarativeWrappingPlugin not declarativePluginApi, will update that for next release. I鈥檓 not sure about crud methods, @Weakky or @jasonkuhrt?
Also thinking maybe we should auto add the plugin for this next release given it鈥檚 been the api for so long.
Also thinking maybe we should auto add the plugin for this next release given it鈥檚 been the api for so long.
Fine with me, should there be a way to uninstall the plugin?
Maybe we can add it like declarativeWrappingPlugin({ installTypes: false }), and then if we detect that the plugin has been installed with the types disabled we warn about the usage. That way things at least start up and print types without needing to fix too many things.
@15chrjef
Regarding the problems with Nexus Plugin Prisma there may be updates needed there, we'll see. Might take another few days to get it up to date with Nexus 0.19. CC @Weakky
Looking forward to updates as they come for nexus-plugin-prisma!
declarativeWrappingPlugin works for me within makeSchema
Most helpful comment
You can import/add the
declarativeWrappingPlugin()to thepluginsarray inmakeSchemaconfig and it will re-enable the previous behavior ofnullable/list/requiredbeing defined on the object literal, but otherwise the preferred api is:alias for
and for args
The chaining API allows for simpler nested list types:
or if you prefer: