Loopwise Docs
Admin APIQueries

Loopwise Admin API Queries

Available query operations, pagination, and filtering for the Loopwise Admin API

Note: The Loopwise Admin API is currently under development and not yet available for public use. This documentation is provided for preview purposes only.

Overview

The Loopwise Admin API provides a variety of query operations to retrieve data from your school. This section documents all available queries, along with concepts like pagination and filtering that apply across multiple query types.

Available Resources

The API provides queries for the following resources:

Common Parameters

All queries accept the following common parameters:

ParameterTypeDescription
firstIntNumber of items to return (default: 20, max: 100)
afterStringCursor for pagination

Basic Example

Here's a simple example of querying for school information:

query {
  school {
    id
    name
    createdAt
  }
}

For more detailed examples and resource-specific queries, explore the resource pages linked above.


Pagination

The Loopwise Admin API uses cursor-based pagination to efficiently handle large datasets. This approach allows you to retrieve data in manageable chunks while maintaining consistent results across requests.

Pagination Structure

All paginated responses follow a consistent structure:

{
  "data": {
    "resourceName": {
      "nodes": [
        // Array of resource objects
      ],
      "pageInfo": {
        "hasNextPage": true,
        "endCursor": "cursor-string"
      }
    }
  }
}

The key components are:

  • nodes: An array containing the requested resources for the current page
  • pageInfo: Metadata about the current page and navigation
    • hasNextPage: Boolean indicating if more results exist beyond this page
    • endCursor: A string cursor that can be used to fetch the next page

Pagination Parameters

When querying paginated resources, you can use these parameters:

ParameterTypeDescription
firstIntNumber of items to return (default: 20, max: 100)
afterStringCursor string from a previous query's endCursor

Pagination Example

Initial Query

To fetch the first page of courses:

query {
  courses(first: 10) {
    nodes {
      id
      name
      description
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

Subsequent Pages

To fetch the next page, use the endCursor from the previous response:

query {
  courses(first: 10, after: "previous-end-cursor") {
    nodes {
      id
      name
      description
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

JavaScript Pagination Example

Here's how to implement pagination in JavaScript:

async function fetchAllCourses(apiKey) {
  const endpoint = 'https://teachify.io/admin/graphql';
  let hasNextPage = true;
  let after = null;
  let allCourses = [];

  while (hasNextPage) {
    const query = `
      query Courses($first: Int, $after: String) {
        courses(first: 25, after: $after) {
          nodes {
            id
            name
            description
          }
          pageInfo {
            hasNextPage
            endCursor
          }
        }
      }
    `;

    const response = await fetch(endpoint, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-Teachify-API-Key': apiKey
      },
      body: JSON.stringify({
        query,
        variables: { first: 25, after }
      })
    });

    const result = await response.json();
    const { nodes, pageInfo } = result.data.courses;

    allCourses = [...allCourses, ...nodes];
    hasNextPage = pageInfo.hasNextPage;
    after = pageInfo.endCursor;

    console.log(`Fetched ${nodes.length} courses. Total so far: ${allCourses.length}`);
  }

  return allCourses;
}

Pagination Best Practices

  1. Use reasonable page sizes: Request only what you need. Smaller page sizes (10-25 items) are better for interactive UIs, while larger sizes (50-100) may be more efficient for data processing.

  2. Always check hasNextPage: Don't assume there are more pages based on the number of items returned.

  3. Store the endCursor: Save the cursor between user interactions or application states to maintain pagination position.

  4. Handle empty results: Your code should gracefully handle cases where no results are returned.

  5. Avoid fetching all pages at once: For very large datasets, consider implementing "load more" or traditional page navigation rather than automatically loading all pages.


Filtering

The Loopwise Admin API supports powerful filtering capabilities that allow you to narrow down query results to exactly what you need. Filtering is performed on the server side, which improves performance by reducing the amount of data transferred.

Filter Structure

Filters are provided as input objects to queries. Each resource type has its own filter input type with fields specific to that resource. For example:

  • CourseFilter for filtering courses
  • StudentFilter for filtering students
  • AssignmentFilter for filtering assignments

Common Filter Types

String Filters

String fields typically support these filtering operations:

OperationDescriptionExample
equalsExact match{ name: { equals: "Math 101" } }
containsContains substring{ name: { contains: "Math" } }
startsWithStarts with substring{ name: { startsWith: "Math" } }
endsWithEnds with substring{ name: { endsWith: "101" } }

Number Filters

Number fields support range operations:

OperationDescriptionExample
equalsExact match{ enrollmentCount: { equals: 25 } }
gtGreater than{ enrollmentCount: { gt: 20 } }
gteGreater than or equal{ enrollmentCount: { gte: 20 } }
ltLess than{ enrollmentCount: { lt: 30 } }
lteLess than or equal{ enrollmentCount: { lte: 30 } }
betweenBetween two values{ enrollmentCount: { between: [20, 30] } }

Date Filters

Date fields support similar operations to number fields:

OperationDescriptionExample
equalsExact date match{ startDate: { equals: "2023-09-01" } }
beforeBefore date{ startDate: { before: "2023-09-01" } }
afterAfter date{ startDate: { after: "2023-09-01" } }
betweenBetween two dates{ startDate: { between: ["2023-09-01", "2023-12-31"] } }

Boolean Filters

Boolean fields can be filtered directly:

{
  isActive: true
}

ID Filters

ID fields support exact match or inclusion in a list:

OperationDescriptionExample
equalsExact ID match{ id: { equals: "course-123" } }
inID in list{ id: { in: ["course-123", "course-456"] } }

Combining Filters

You can combine multiple filters in a single query. By default, all conditions must be met (AND logic):

query {
  courses(
    filter: {
      name: { contains: "Math" }
      startDate: { after: "2023-01-01" }
      enrollmentCount: { gt: 10 }
    }
  ) {
    nodes {
      id
      name
    }
  }
}

Logical Operators

For more complex filtering, you can use logical operators:

AND

query {
  courses(
    filter: {
      AND: [
        { name: { contains: "Math" } },
        { enrollmentCount: { gt: 10 } }
      ]
    }
  ) {
    nodes {
      id
      name
    }
  }
}

OR

query {
  courses(
    filter: {
      OR: [
        { name: { contains: "Math" } },
        { name: { contains: "Science" } }
      ]
    }
  ) {
    nodes {
      id
      name
    }
  }
}

NOT

query {
  courses(
    filter: {
      NOT: {
        name: { contains: "Archived" }
      }
    }
  ) {
    nodes {
      id
      name
    }
  }
}

You can filter based on related resources. For example, finding courses with specific instructors:

query {
  courses(
    filter: {
      instructors: {
        some: {
          name: { contains: "Smith" }
        }
      }
    }
  ) {
    nodes {
      id
      name
    }
  }
}

Resource-Specific Filters

Each resource type has specific filter fields. For detailed information on available filters for each resource, see the resource-specific documentation:

Filtering Best Practices

  1. Filter on the server: Always use API filtering instead of retrieving large datasets and filtering client-side.

  2. Be specific: Use the most specific filter operations available to minimize data transfer.

  3. Combine with pagination: Use filtering together with pagination for the most efficient queries.

  4. Test complex filters: Complex logical combinations should be thoroughly tested to ensure they return the expected results.

On this page