### Monorepo Build Workflow with Bash
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
This section details the commands to build all packages within the monorepo using Preconstruct. It includes steps for installing dependencies, building packages, and starting development servers.
```bash
# Install dependencies for all packages
yarn
# Build all packages (creates dist files)
yarn build
# Expected output:
# ✨ @monorepo-starter/button success
# ✨ @monorepo-starter/graphql-api success
# Start the GraphQL server
yarn start:server
# In another terminal, start the Next.js app
yarn start:next
# Visit http://localhost:3000 to see the app running
```
--------------------------------
### Monorepo Package Installation with Bash
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Provides commands for managing package dependencies within the monorepo. It covers installing dependencies for the entire monorepo, individual packages, and checking/fixing version conflicts using `manypkg`.
```bash
# Install a dependency for the entire monorepo
yarn add lodash -W
# Install a dependency for a specific package
cd packages/button
yarn add prop-types
# Return to root and install all dependencies
cd ../..
yarn
# Check for version conflicts across packages
yarn manypkg check
# Auto-fix version conflicts
yarn manypkg fix
```
--------------------------------
### Next.js Apollo Client Setup
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Configuration for Apollo Client within a Next.js application. This setup enables the frontend application to efficiently interact with the GraphQL API, demonstrating client-side integration patterns.
```javascript
import React from "react";
import fetch from "isomorphic-unfetch";
import ApolloClient from "apollo-boost";
import { ApolloProvider } from "@apollo/react-hooks";
// Initialize Apollo Client
const client = new ApolloClient({
uri: "http://localhost:4000/",
fetch
});
// Wrap your Next.js app with ApolloProvider
const App = ({ Component, pageProps }) => (
);
export default App;
```
--------------------------------
### Monorepo Cleanup with Bash
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Explains how to clean generated files and dependencies across all packages in the monorepo. This includes removing `node_modules` and `dist` folders to allow for a fresh installation.
```bash
# Clean all node_modules and dist folders
yarn clean
# Expected behavior:
# - Removes node_modules from root
# - Removes node_modules from each package
# - Removes dist folders from each package
# - Allows fresh reinstall with: yarn
# After cleanup, reinstall
yarn
```
--------------------------------
### Apollo React Hooks - useLazyQuery in JavaScript
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Shows how to use the `useLazyQuery` hook from `@apollo/react-hooks` to execute GraphQL queries on demand, typically triggered by user interaction. This example fetches author details based on a name.
```javascript
import React from "react";
import Button from "@monorepo-starter/button";
import { useLazyQuery } from "@apollo/react-hooks";
import { gql } from "apollo-boost";
const getAuthorDetails = gql`
query($name: String) {
author(name: $name) {
name
books {
title
}
}
}
`;
function AuthorDetails() {
const [getAuthor, { loading, error, data }] = useLazyQuery(getAuthorDetails);
return (
{loading &&
Loading...
}
{error &&
Error: {error.message}
}
{data && (
{data.author.name}
{data.author.books.map(({ title }) => (
{title}
))}
)}
);
}
export default AuthorDetails;
```
--------------------------------
### GraphQL API Query Authors (cURL)
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Example using cURL to query all authors from the GraphQL API. This demonstrates how to interact with the backend service from external clients, showcasing a common use case for API testing and integration.
```bash
# Query all authors
curl -X POST http://localhost:4000/ \
-H "Content-Type: application/json" \
-d '{
"query": "{ authors { name } }"
}'
# Expected response:
# {
# "data": {
# "authors": [
# { "name": "Ann Leckie" },
# { "name": "N K Jemisin" },
# { "name": "Melissa Caruso" }
# ]
# }
# }
```
--------------------------------
### GraphQL API Query Author with Books (cURL)
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Example using cURL to query a specific author and their books from the GraphQL API. This demonstrates parameterized queries, a powerful feature for fetching specific data relationships from the backend.
```bash
# Query specific author with their books
curl -X POST http://localhost:4000/ \
-H "Content-Type: application/json" \
-d '{
"query": "query($name: String) { author(name: $name) { name books { title } } }",
"variables": { "name": "Ann Leckie" }
}'
# Expected response:
# {
# "data": {
# "author": {
# "name": "Ann Leckie",
# "books": [
# { "title": "Ancillary Justice" },
# { "title": "The Raven Tower" }
# ]
# }
# }
# }
```
--------------------------------
### Linting with Bash
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Describes how to run ESLint for code quality checks across the entire monorepo. It provides commands for linting all files and for linting with auto-fixing capabilities.
```bash
# Lint all files
yarn lint
# Lint and auto-fix issues
yarn lint --fix
# Expected output (if no errors):
# ✨ All files passed linting!
# With errors:
# /packages/button/src/index.js
# 12:5 error Missing semicolon semi
#
# ✖ 1 problem (1 error, 0 warnings)
```
--------------------------------
### Changesets Workflow for Versioning and Changelogs with Bash
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
This outlines the workflow for managing package versions and changelogs using Changesets. It includes commands to create, version, and release packages based on defined changesets.
```bash
# Create a changeset for your changes
yarn changeset
# Follow the prompts:
# 1. Select packages that changed (space to select)
# 2. Choose bump type (major/minor/patch)
# 3. Write a summary of changes
# Version packages based on changesets
yarn changeset version
# Build and publish packages
yarn release
# Example changeset file (.changeset/cool-feature.md):
# ---
# "@monorepo-starter/button": minor
# ---
#
# Added support for disabled state in Button component
```
--------------------------------
### Apollo React Hooks - useQuery in JavaScript
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Demonstrates how to use the `useQuery` hook from `@apollo/react-hooks` to fetch data in React components. It handles loading, error, and data states, rendering a list of authors.
```javascript
import React from "react";
import { useQuery } from "@apollo/react-hooks";
import { gql } from "apollo-boost";
const getAuthors = gql`
query {
authors {
name
}
}
`;
function AuthorList() {
const { data, loading, error } = useQuery(getAuthors);
if (loading) return
Loading authors...
;
if (error) return
Error loading authors: {error.message}
;
if (!data) return null;
return (
Authors
{data.authors.map(({ name }) => (
{name}
))}
);
}
export default AuthorList;
```
--------------------------------
### GraphQL API Server Implementation
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
An Apollo Server implementation for a GraphQL API. This server provides endpoints to query authors and their associated books. It defines the data types and resolvers for the API schema, demonstrating backend service integration.
```javascript
import { ApolloServer, gql } from "apollo-server";
// Start the GraphQL server
const typeDefs = gql`
type Query {
authors: [Author]
author(name: String): Author
}
type Book {
title: String
author: Author
}
type Author {
name: String
books: [Book]
}
`;
const resolvers = {
Query: {
authors() {
return authors;
},
author(_, { name }) {
return authors.find(author => author.name === name);
}
},
Author: {
books(author) {
return books.filter(book => book.author === author.name);
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
// Expected output: 🚀 Server ready at http://localhost:4000/
```
--------------------------------
### Running Tests with Bash
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Details the commands to execute Jest tests across all packages in the monorepo. It includes options for running tests normally, in watch mode, and with coverage reporting.
```bash
# Run all tests
yarn test
# Run tests in watch mode
yarn test --watch
# Run tests with coverage
yarn test --coverage
# Expected output:
# PASS packages/button/src/__tests__/index.test.js
# PASS services/graphql-api/src/__tests__/index.test.js
#
# Test Suites: 2 passed, 2 total
# Tests: 5 passed, 5 total
```
--------------------------------
### React Button Component Usage
Source: https://context7.com/thinkmill/monorepo-starter/llms.txt
Demonstrates how to use a reusable React button component. This component allows for customizable styling based on its selection state. It is a common pattern for building interactive UI elements within a monorepo.
```javascript
import React from "react";
import Button from "@monorepo-starter/button";
function App() {
const [selectedButton, setSelectedButton] = React.useState(null);
return (
);
}
export default App;
```
--------------------------------
### TypeScript Package Configuration
Source: https://github.com/thinkmill/monorepo-starter/blob/master/README.md
Configuration for individual React packages within the monorepo. It extends the React base configuration and specifies the source directory for compilation.
```json
{
"extends": "../../tsconfig.react.json",
"include": ["src"]
}
```
--------------------------------
### TypeScript Base Configuration
Source: https://github.com/thinkmill/monorepo-starter/blob/master/README.md
Defines the base TypeScript configuration for a monorepo project, including module resolution, target, and library settings. This serves as a foundation for other tsconfig files.
```json
{
"compilerOptions": {
"module": "esnext",
"target": "es5",
"moduleResolution": "node",
"esModuleInterop": true,
"lib": ["dom", "esnext"],
"importHelpers": true,
"rootDir": "./",
"sourceMap": true,
"declaration": true,
"baseUrl": "./"
}
}
```
--------------------------------
### TypeScript React Configuration
Source: https://github.com/thinkmill/monorepo-starter/blob/master/README.md
Extends the base TypeScript configuration to include React-specific settings, such as JSX compilation. This file should be extended by individual React package configurations.
```json
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"jsx": "react"
}
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.