Comments (7)
I used to face the same problem, and found it's my misunderstood in writing of resolver function.
{"errors":[{"message":"Resolve function missing for \"RootQuery.Config\""}]}
export const resolvers = {
RootMutation: {
getToken(root, { username, password }, context) {
return context.User.login(username, password);
},
},
RootQuery: {
Config: {
alarmTypes(_, __, context) {
return context.Config.getAlarmTypes();
},
},
},
ConfigType: {
alarmTypes(_, __, context) {
return context.Config.getAlarmTypes();
},
},
AlarmCodeType: {
code(a, b, c) {
console.log(a, b, c);
},
label(a, b, c) {
console.log(a, b, c);
},
},
};
export const typeDefinitions = `schema {
query: RootQuery
mutation: RootMutation
}
type RootMutation {
getToken(username: String!, password: String!): TokenType
}
type TokenType {
token: String!
error: String!
}
type RootQuery {
Config: ConfigType
#User: UserType
#Company: PowerEntityType
}
type ConfigType {
alarmTypes: [AlarmCodeType!]
}
type AlarmCodeType {
code: Int!
label: String!
}
Now I write:
export const resolvers = {
RootMutation: {
getToken(root, { username, password }, context) {
return context.User.login(username, password);
},
},
RootQuery: {
Config(root, args, context) {
return context.Config.getAlarmTypes();
},
},
ConfigType: {
alarmTypes(_, __, context) {
return context.Config.getAlarmTypes();
},
},
AlarmCodeType: {
code(a, b, c) {
console.log(a, b, c);
},
label(a, b, c) {
console.log(a, b, c);
},
},
};
it's ok now
from graphql-tools.
Hi, I can't understood it. Can anyone help me to get what the last informated defining.
And i am facing the same issue.. when i try to merge the schemas and resolvers of 2 models called product and users.. and i am new graphql.
If anyone redirect me to the right path for merging two models then it is very favourable to me.
I am creating API using graphql-tools and apollo-server..
`module.exports =
type product {
id: ID
userId: Int
description: String
images: [String]
categoryId: Int
viewers: [Int]
city: String
state: String
country: String
latitude: String
longitude: String
isFree: Boolean
createdAt: String
updatedAt: String
likedUsers: [Int]
status: String
make: String
model: String
year: Int
serviceCategory: String
service: String
rate: Int
currencyCode: String
bodyType: String
transmission: String
fuelType: String
driveTrain: String
seats: String
mileage: Int
}
type Query {
getProduct: product
getAllProducts: [product]
}
input productData {
description: String
images: [String]
categoryId: Int
city: String
state: String
country: String
latitude: String
longitude: String
isFree: Boolean
make: String
model: String
year: Int
serviceCategory: String
service: String
rate: Int
currencyCode: String
bodyType: String
transmission: String
fuelType: String
driveTrain: String
seats: String
mileage: Int
}
type Mutation {
createProduct(data: productData): product
editProduct( id: Int!, userId: Int!, data: productData): product
};`
`const resolvers = {
Query: {
getProduct: async (root, {id}, {currentUser, product}) => {
console.log(args, user, currentUser);
if (!currentUser) {
throw new Error('User Not Authenticated');
} else {
const foundProduct = await product.findOne({id});
return foundProduct;
}
},
getAllProducts: async(root, args, {currentUser, product}) => {
console.log(args, product, currentUser);
const products = await product.find();
return products;
}
},
Mutation: {
createProduct: async (root, args, {currentUser, product}) => {
if(!currentUser) {
throw new Error('User Not Authenticated');
} else {
const newProduct = await new product(args).save();
return newProduct;
}
},
editProduct: async (root, {id, userId, data}, {currentUser, product}) => {
if (!currentUser) {
throw new Error('User Not Authenticated');
} else if (currentUser.id !== userId) {
throw new Error('This user have no permissions to edit this product');
} else {
const foundProduct = await product.findOneAndUpdate({id}, {$set: data}, {new: true});
if(!foundProduct){
throw new Error('Product Not Found');
}
return foundProduct;
}
}
}
};
module.exports = resolvers;`
`module.exports =
type User {
id: ID
firstName: String!
lastName: String!
password: String!
bio: String
profileImage: String
email: String! @unique
currencyCode: String
TimeZone: Int
status: String
conversationId: Int
faceBookId: String
googleId: String
deviceId: String
blocked: [Int]
favourites: [Int]
faceBookVerified: Boolean
googleVerified: Boolean
phoneVerified: Boolean
emailVerified: Boolean
rememberToken: String
phone: Int
createdAt: String
updatedAt: String
city: String
state: String
country: String
latitude: String
longitude: String
unit: String
radius: Float
}
type Token {
token: String!
}
type Query {
getCurrentUser: User
}
input userInput {
firstName: String,
lastName: String,
email: String,
bio: String,
profileImage: String,
password: String,
city: String
state: String
country: String
latitude: String
longitude: String
unit: String
radius: Float
}
type Mutation {
signup(deviceId: String, googleId: String, facebookId: String, firstName: String!, lastName: String!, email: String!, password: String, profileImage: String): Token
signin(deviceId: String, googleId: String, facebookId: String, email: String!, password: String!, profileImage: String): Token
editProfile(email: String!, data: userInput): User
};`
`const jwt = require('jsonwebtoken');
var bcrypt = require('bcrypt');
const createToken = (user, secret, expiresIn) => {
const { firstName, email, id} = user;
return jwt.sign({firstName, email, id}, secret, {expiresIn})
};
const resolvers = {
Query: {
getCurrentUser: async (root, args, {user, currentUser}) => {
if (!currentUser) {
throw new Error('User Not Authenticated');
} else {
const foundUser = await user.findOne({email: currentUser.email});
return foundUser;
}
}
},
Mutation: {
signup: async (root, args, {user}) => {
console.log(args);
const foundUser = await user.findOne({email: args.email}).exec();
if(foundUser) {
throw new Error('User already exits');
}
const newUser = await new user(args).save();
return {token: createToken(newUser, process.env.JWT_SECRET, "1yr")};
},
signin: async (root, {email, password}, {user}) => {
const foundUser = await user.findOne({email});
if(!foundUser){
throw new Error('User Not Found');
}
const isValidPassword = await bcrypt.compare(password, foundUser.password);
if(!isValidPassword){
throw new Error('inValid password');
}
return {token: createToken(foundUser, process.env.JWT_SECRET, "1yr")};
},
editProfile: async (root, {email, data}, {currentUser, user}) => {
if(!currentUser) {
throw new Error('User Not Authenticated');
} else {
if (!!data.password) {
const saltRounds = 10;
data.password = await bcrypt.hash(data.password, saltRounds);
}
const foundUser = await user.findOneAndUpdate({email}, {$set: data}, {new: true});
if(!foundUser){
throw new Error('User Not Found');
}
return foundUser;
}
}
}
};
module.exports = resolvers;
`
I want to combine those 2 schemas and resolvers to pass it as a single thing in a server file using makexecuable schema.. But I can't merge those both things, I am getting errors...
from graphql-tools.
@lawanyaselvamani Please format your code.
from graphql-tools.
@maytis You can find the documentation here: http://docs.apollostack.com/graphql-tools/generate-schema.html
There's a second option in resolverValidationOptions
, which is called requireResolversForArgs
, presumably you want to set that to false as well.
from graphql-tools.
Thanks helfer, From the example, I should pass jsSchema to Schema attribute in ApolloServer or as object ? Since, resolvers are already being passed on to the jsSchema.
from graphql-tools.
The schema passed to apollo server should be an instance of GraphQLSchema
from the graphql npm package.
from graphql-tools.
@maytis were you able to resolve the issue?
from graphql-tools.
Related Issues (20)
- GraphQLSchema from stitchSchema causes scalar values to be parsed twice HOT 1
- Allow sorting only top level declarations in schema HOT 1
- `@graphql-tools/mock` - controllable randomness when mocking out union types
- processImport seems unnecessarily slow due to graphql.print HOT 1
- SSE stream breaks when response data is large HOT 2
- Allow for empty objects in mock store HOT 2
- Apollo Subgraph entities are not resolved when using `wrapSchema` HOT 13
- getLoader in batch-delegate uses a non-unique cacheKey HOT 1
- graphql-ws executor does not resolve `connectionParams`
- Project Roadmap HOT 2
- Drop dependency on fast-url-parser HOT 2
- DEBUG=1 results in console.time() warnings
- @graphql-tools/mock does not work with Vitest HOT 5
- Deterministic (seeded) enum values
- Stitching: object field is null when all selections are delegated
- Http Executor encodes headers into query parameters which can leak Authorization headers
- Ability to get names of all the stitched queries in a middleware
- requireResolversToMatchSchema: 'warn' throws an error
- Support .astro file loading on graphql-tag-pluck HOT 1
- Troubles with connectionParams on subscriptions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-tools.