initial update
This commit is contained in:
56
index.ts
Normal file
56
index.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
// server/index.ts (or server.js if not using TypeScript)
|
||||
|
||||
import { ApolloServer } from '@apollo/server';
|
||||
import { startStandaloneServer } from '@apollo/server/standalone';
|
||||
import { gql } from 'graphql-tag';
|
||||
import { sendEmail } from './sendEmail.ts';
|
||||
|
||||
const typeDefs = gql`
|
||||
input FormInput {
|
||||
name: String!
|
||||
email: String!
|
||||
phone: String
|
||||
location: String
|
||||
info: String
|
||||
}
|
||||
|
||||
type SubmitResponse {
|
||||
success: Boolean!
|
||||
message: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
submitForm(input: FormInput!): SubmitResponse!
|
||||
}
|
||||
|
||||
type Query {
|
||||
_empty: String
|
||||
}
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Mutation: {
|
||||
submitForm: async (_: any, { input }: any) => {
|
||||
console.log("Form received:", input);
|
||||
|
||||
await sendEmail(input);
|
||||
|
||||
// Simulate saving to DB, etc.
|
||||
return {
|
||||
success: true,
|
||||
message: 'Form submitted successfully!',
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
});
|
||||
|
||||
startStandaloneServer(server, {
|
||||
listen: { port: 4000 },
|
||||
}).then(({ url }) => {
|
||||
console.log(`🚀 Server ready at ${url}`);
|
||||
});
|
||||
Reference in New Issue
Block a user