useQuery fix
This commit is contained in:
@@ -30,33 +30,33 @@ app.use('/graphql', graphqlHTTP({
|
||||
}));
|
||||
|
||||
const server = new ApolloServer({
|
||||
// typeDefs: fs.readFileSync(
|
||||
// path.join(__dirname, 'schema.graphql'),
|
||||
// 'utf8'
|
||||
// ),
|
||||
schema,
|
||||
typeDefs: fs.readFileSync(
|
||||
path.join(__dirname, 'schema.graphql'),
|
||||
'utf8'
|
||||
),
|
||||
// schema,
|
||||
cors: true,
|
||||
playground: process.env.NODE_ENV === 'development' ? true : false,
|
||||
// context: async ({ req }) => {
|
||||
// // if (!db) {
|
||||
// // try {
|
||||
// // if (!dbClient.isConnected()) await dbClient.connect()
|
||||
// // mongo = dbClient.db('Calendar') // database name
|
||||
// // console.log(db);
|
||||
// // } catch (e) {
|
||||
// // console.log('--->error while connecting with graphql context (db)', e)
|
||||
// // }
|
||||
context: async ({ req }) => {
|
||||
// if (!db) {
|
||||
// try {
|
||||
// if (!dbClient.isConnected()) await dbClient.connect()
|
||||
// mongo = dbClient.db('Calendar') // database name
|
||||
// console.log(db);
|
||||
// } catch (e) {
|
||||
// console.log('--->error while connecting with graphql context (db)', e)
|
||||
// }
|
||||
|
||||
// return {
|
||||
// ...req,
|
||||
// mongoose,
|
||||
// pubsub,
|
||||
// userId:
|
||||
// req && req.headers.authorization
|
||||
// ? getUserId(req)
|
||||
// : null
|
||||
// }
|
||||
// },
|
||||
return {
|
||||
...req,
|
||||
mongoose,
|
||||
pubsub,
|
||||
// userId:
|
||||
// req && req.headers.authorization
|
||||
// ? getUserId(req)
|
||||
// : null
|
||||
}
|
||||
},
|
||||
// subscriptions: {
|
||||
// onConnect: (connectionParams) => {
|
||||
// if (connectionParams.authToken) {
|
||||
|
||||
25
server/src/models/appointment.js
Normal file
25
server/src/models/appointment.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import mongoose from 'mongoose';
|
||||
const Schema = mongoose.Schema;
|
||||
const AppointmentSchema = new Schema({
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
timeStart: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
timeEnd: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
}
|
||||
});
|
||||
export default mongoose.model('appointment', AppointmentSchema);
|
||||
@@ -1,14 +1,14 @@
|
||||
// import Appointment from '../../client/src/components/Appointment.js';
|
||||
import Product from './models/product.js';
|
||||
import Appointment from './models/appointment.js';
|
||||
|
||||
export const resolvers = {
|
||||
Query: {
|
||||
async allProducts() {
|
||||
const products = await Product.find();
|
||||
console.log("Tah!", products);
|
||||
return products;
|
||||
// return {
|
||||
// products
|
||||
// };
|
||||
return await Product.find();
|
||||
},
|
||||
async allAppointments() {
|
||||
return await Appointment.find();
|
||||
},
|
||||
},
|
||||
Mutation: {
|
||||
|
||||
@@ -7,6 +7,7 @@ type Query {
|
||||
orderBy: AppointmentOrderByInput
|
||||
): Feed!
|
||||
allProducts: [Product]
|
||||
allAppointments: [Appointment]
|
||||
users: [User!]!
|
||||
}
|
||||
|
||||
@@ -20,8 +21,8 @@ type Mutation {
|
||||
createAppointment(
|
||||
title: String!,
|
||||
description: String!,
|
||||
start: DateTime!,
|
||||
end: DateTime!,
|
||||
timeStart: DateTime!,
|
||||
timeEnd: DateTime!,
|
||||
): Appointment!
|
||||
createProduct(
|
||||
input: ProductInput
|
||||
@@ -58,31 +59,32 @@ type AuthPayload {
|
||||
}
|
||||
|
||||
type User {
|
||||
id: ID!
|
||||
_id: ID!
|
||||
name: String!
|
||||
email: String!
|
||||
appointments: [Appointment!]!
|
||||
}
|
||||
|
||||
type Appointment {
|
||||
id: ID!
|
||||
_id: ID!
|
||||
title: String!
|
||||
description: String!
|
||||
start: DateTime!
|
||||
end: DateTime!
|
||||
createdBy: User
|
||||
follows: [Follow!]!
|
||||
createdAt: DateTime!
|
||||
timeStart: DateTime!
|
||||
timeEnd: DateTime!
|
||||
deleted: Boolean
|
||||
# createdBy: User
|
||||
# follows: [Follow!]!
|
||||
# createdAt: DateTime!
|
||||
}
|
||||
|
||||
type Product {
|
||||
id: ID!
|
||||
_id: ID!
|
||||
title: String!
|
||||
qty: Int
|
||||
}
|
||||
|
||||
type Follow {
|
||||
id: ID!
|
||||
_id: ID!
|
||||
appointment: Appointment!
|
||||
user: User!
|
||||
}
|
||||
|
||||
@@ -1,54 +1,19 @@
|
||||
// import {
|
||||
// makeExecutableSchema
|
||||
// } from 'graphql-tools';
|
||||
// import {
|
||||
// resolvers
|
||||
// } from './resolvers.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { makeExecutableSchema } from 'graphql-tools';
|
||||
import { resolvers } from './resolvers.js';
|
||||
|
||||
// import fs from 'fs';
|
||||
// import path from 'path';
|
||||
const moduleURL = new URL(import.meta.url);
|
||||
const __dirname = path.dirname(moduleURL.pathname);
|
||||
|
||||
// const moduleURL = new URL(import.meta.url);
|
||||
// const __dirname = path.dirname(moduleURL.pathname);
|
||||
const typeDefs = fs.readFileSync(
|
||||
path.join(__dirname, 'schema.graphql'),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
// const typeDefs = fs.readFileSync(
|
||||
// path.join(__dirname, 'schema.graphql'),
|
||||
// 'utf8'
|
||||
// );
|
||||
// const schema = makeExecutableSchema({
|
||||
// typeDefs,
|
||||
// // resolvers
|
||||
// });
|
||||
// export default schema;
|
||||
|
||||
|
||||
import {
|
||||
makeExecutableSchema
|
||||
} from 'graphql-tools';
|
||||
import {
|
||||
resolvers
|
||||
} from './resolvers.js';
|
||||
const typeDefs = `
|
||||
type Product {
|
||||
_id: ID!
|
||||
title: String!
|
||||
qty: Int
|
||||
}
|
||||
type Query {
|
||||
allProducts: [Product]
|
||||
}
|
||||
input ProductInput {
|
||||
title: String!
|
||||
qty: Int
|
||||
}
|
||||
type Mutation {
|
||||
createProduct(input: ProductInput) : Product
|
||||
updateProduct(_id: ID!, input: ProductInput): Product
|
||||
deleteProduct(_id: ID!) : Product
|
||||
}
|
||||
`;
|
||||
const schema = makeExecutableSchema({
|
||||
typeDefs,
|
||||
resolvers
|
||||
});
|
||||
export default schema;
|
||||
|
||||
export default schema;
|
||||
|
||||
Reference in New Issue
Block a user