57 lines
1.1 KiB
TypeScript
57 lines
1.1 KiB
TypeScript
// 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}`);
|
|
});
|