The adaptic-backend
repository provides a comprehensive collection of TypeScript type definitions that correspond to the various models and input types used in the Adaptic backend. These type definitions are crucial for ensuring type safety and consistency across backend operations, particularly when interacting with GraphQL queries, mutations, and Prisma models. By utilizing these type definitions, developers can build and maintain robust and scalable backend applications with confidence.
- fix-import-paths.js # Automates the process of fixing import paths in generated TypeGraphQL Prisma resolver output files.
- package.json # Manages project configurations, scripts, and dependencies.
- schema.prisma # Defines the data model for the application, establishing the structure of the database.
- src/
- types/ # Contains the TypeScript type definitions for the various models and input types.
- auth.ts # Implements JWT authentication middleware to secure routes.
- server.ts # Sets up the Express server integrated with Apollo Server for GraphQL requests and real-time updates.
- tsconfig.json # Configures TypeScript compiler options for the project.
This repository offers a robust set of TypeScript type definitions for a comprehensive backend solution. Key features include:
Before you begin, ensure you have the following prerequisites set up:
The following NPM packages are required:
typescript
@types/node
@apollo/server
@prisma/client
graphql
type-graphql
git clone https://github.com/Adaptic-ai/adaptic-backend.git
cd adaptic-backend
Follow these steps to install dependencies and set up the environment:
Install NPM Dependencies:
npm install
Set Up Environment Variables:
Create a .env
file in the root of the project and add:
DATABASE_URL=your_database_connection_string
JWT_SECRET=your_jwt_secret
PORT=4000
Run the Application: Start the server:
npm run start
Your backend server should now be up and running, ready to handle GraphQL requests and manage user authentication!
You can import and use the type definitions provided by the adaptic-backend
package to ensure type safety in your application. Here’s how to do it:
User Authentication
username
: String (required)password
: String (required)For example, to use the Workspace
type definition:
import { Workspace } from 'adaptic-backend/types';
// Example usage of the Workspace type
const myWorkspace: Workspace = {
id: 'workspace-id',
name: 'My Workspace',
createdAt: new Date(),
updatedAt: new Date(),
};
User Authentication
{
"token": "JWT_TOKEN_STRING",
"user": {
"id": "USER_ID",
"username": "USERNAME"
}
}
When performing a GraphQL query or mutation, you can use the imported type definitions to ensure your variables and data are correctly typed:
import { gql } from '@apollo/client';
import { WorkspaceInput } from 'adaptic-backend/types';
To test the backend, use the following sample data:
- **User Credentials**
- Username: `testuser`
- Password: `password123`
- **GraphQL Query Example**
```graphql
query {
user(id: "USER_ID") {
id
name
}
}
`;
// Example usage with the WorkspaceInput type
const newWorkspace: WorkspaceInput = {
name: 'New Workspace',
};
const createWorkspace = async () => {
const response = await apolloClient.mutate({
mutation: CREATE_WORKSPACE,
variables: { input: newWorkspace },
});
console.log(response.data);
};
const authenticateUser = async (username, password) => {
const response = await fetch('http://localhost:PORT/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `
mutation {
login(username: "${username}", password: "${password}") {
token
user {
id
username
}
}
}
`
})
})
const data = await response.json()
return data
}
// Usage
authenticateUser('testuser', 'password123').then(console.log)
const fetchUserData = async userId => {
const response = await fetch('http://localhost:PORT/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `
query {
user(id: "${userId}") {
id
username
email
}
}
`
})
})
const data = await response.json()
return data
}
// Usage
fetchUserData('USER_ID').then(console.log)
We welcome contributions to the adaptic-backend
repository! To contribute, please follow these guidelines:
git clone https://github.com/YOUR_USERNAME/adaptic-backend.git
git checkout -b feature/your-feature-name
git commit -m "Add your message here"
git push origin feature/your-feature-name
Please ensure that your code adheres to the existing style and includes appropriate tests.
This repository is licensed under the MIT License. See the LICENSE file for more details.
We would like to thank the open-source community for their contributions and support.
This project is a product of Adaptic.ai.
Thanks for reading this far! Why did the developer go broke? Because he used up all his cache!