Category: Lineserve

  • How to Install Git

    Installing Git is straightforward, and the process varies slightly depending on your operating system. Here’s how to install Git on **Windows**, **macOS**, and **Linux**:\n\n—\n\n### **1. Install Git on Windows**\n#### **Option 1: Install Git via Official Installer**\n1. **Download Git** from the official website: \n → [https://git-scm.com/download/win](https://git-scm.com/download/win)\n2. **Run the installer** (`Git-x.x.x-64-bit.exe`).\n3. Follow the setup wizard (default options are fine for most users).\n4. **Verify installation** by opening **Command Prompt** (`cmd`) and running:\n “`sh\n git –version\n “`\n\n#### **Option 2: Install Git via Winget (Windows Package Manager)**\nRun in **PowerShell** or **Command Prompt**:\n“`sh\nwinget install –id Git.Git -e –source winget\n“`\n\n—\n\n### **2. Install Git on macOS**\n#### **Option 1: Install Git via Homebrew (Recommended)**\n1. Open **Terminal**.\n2. Install **Homebrew** (if not already installed):\n “`sh\n /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”\n “`\n3. Install Git:\n “`sh\n brew install git\n “`\n4. Verify:\n “`sh\n git –version\n “`\n\n#### **Option 2: Install Git via Xcode Command Line Tools**\nRun in **Terminal**:\n“`sh\nxcode-select –install\n“`\nThis will install Git along with other developer tools.\n\n—\n\n### **3. Install Git on Linux**\n#### **Debian/Ubuntu (apt)**\n“`sh\nsudo apt update && sudo apt install git -y\n“`\n\n#### **Fedora (dnf)**\n“`sh\nsudo dnf install git -y\n“`\n\n#### **Arch Linux (pacman)**\n“`sh\nsudo pacman -S git\n“`\n\n#### **Verify Installation**\n“`sh\ngit –version\n“`\n\n—\n\n### **Post-Installation Setup (Recommended)**\nAfter installing Git, configure your username and email (required for commits):\n“`sh\ngit config –global user.name “Your Name”\ngit config –global user.email “[email protected]”\n“`\nCheck your settings:\n“`sh\ngit config –list\n“`\n\n—\n\n### **Next Steps**\n- Learn basic Git commands (`git clone`, `git add`, `git commit`, `git push`).\n- Use a GUI tool like **GitHub Desktop**, **Sourcetree**, or **VS Code Git integration**.\n\nLet me know if you need help with any step! 🚀

  • How to Query WordPress Posts with WPGraphQL and cURL

    If you’ve ever wanted to pull WordPress content into an app, static site, or dashboard without dealing with the REST API, WPGraphQL is a powerful plugin that exposes your WordPress data as a GraphQL endpoint. In this guide, we’ll focus on how to query posts directly — including getting a single post or a list of the latest posts — using curl from the command line.


    1. Install WPGraphQL

    In your WordPress dashboard:

    1. Go to Plugins → Add New
    2. Search for “WPGraphQL”
    3. Install and activate the plugin

    This will create a new endpoint:

    https://yourdomain.com/graphql
    

    2. Get the Latest Posts with cURL

    Run the following command, replacing the domain with your own:

    curl -X POST https://yourdomain.com/graphql \
      -H "Content-Type: application/json" \
      -d '{
        "query": "{ posts(first: 5) { nodes { id title excerpt date uri } } }"
      }'
    

    What this does:

    • Sends a POST request to the /graphql endpoint
    • Requests the first 5 posts, returning id, title, excerpt, date, and uri

    3. Get a Single Post by Slug with cURL

    If you know the slug of your post (for example, hello-world), you can fetch it directly:

    curl -X POST https://yourdomain.com/graphql \
      -H "Content-Type: application/json" \
      -d '{
        "query": "query GetPostBySlug($slug: ID!) { post(id: $slug, idType: SLUG) { id title content date uri } }",
        "variables": { "slug": "hello-world" }
      }'
    

    Key points:

    • post query fetches a single post instead of an array
    • idType: SLUG tells GraphQL to interpret the ID as a post slug
    • The variables object passes the slug value dynamically

    4. Common Field Options

    WPGraphQL lets you fetch more than just titles and content. Some useful fields include:

    • author { node { name } } → Get the author’s name
    • featuredImage { node { sourceUrl } } → Get the post’s featured image URL
    • categories { nodes { name slug } } → Get category data

    Example:

    {
      post(id: "hello-world", idType: SLUG) {
        title
        author { node { name } }
        featuredImage { node { sourceUrl } }
        categories { nodes { name slug } }
      }
    }
    

    5. Why Use WPGraphQL Over REST API?

    • Flexible: You choose exactly which fields you want — no over-fetching
    • Single request: Get all related data in one query
    • Structured: Responses are predictable and match your query shape

    Conclusion

    With WPGraphQL, you can turn your WordPress site into a modern, headless CMS that’s easy to integrate into apps and frontends. Using curl is a quick way to test queries before integrating them into your codebase. Once you’ve mastered the basics, you can use advanced GraphQL features like fragments, filtering, and pagination to tailor your data fetching even further.