Download the PHP package rebing/graphql-laravel-select-fields without Composer

On this page you can find all versions of the php package rebing/graphql-laravel-select-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package graphql-laravel-select-fields

SelectFields for graphql-laravel

Latest Stable Version License Tests Downloads Get on Slack

Optimizes GraphQL queries backed by Eloquent models. Analyzes the GraphQL request's field selection to generate minimal SELECT columns and eager-load only the requested relations - preventing N+1 queries and over-fetching.

This is an optional companion package for rebing/graphql-laravel.

Requirements

Installation

The package auto-discovers its service provider. No manual registration is needed. On boot it:

  1. Registers a ResolverParameterInjector so that Closure and SelectFields type-hints in resolver methods work automatically.
  2. Replaces the core pagination types with SelectFields-aware subclasses that implement WrapType and mark metadata fields as non-selectable.

Quick Start

1. Add model to your Type:

2. Use $getSelectFields in your Query:

When a client queries { users { id email posts { title } } }, SelectFields generates:

Only the requested columns are fetched, and the posts relation is eager-loaded in a single query.

Usage

Resolver Injection Patterns

SelectFields can be injected into your resolve() method in two ways.

Closure (lazy - recommended)

The SelectFields instance is only constructed when you call $getSelectFields(). If your resolver has an early return path (cache hit, authorization check), you avoid the cost of walking the query plan.

Class (eager)

The SelectFields instance is constructed before your resolver runs.

Type Configuration

The model Attribute

The model attribute on your Type's $attributes array is required for SelectFields to work. It enables:

Without model, SelectFields operates in a degraded mode - no table qualification, no primary key inclusion, no relation detection.

Field Configuration Keys

These keys can be placed in the arrays returned by your Type's fields() method:

Key Type Default Purpose
selectable bool true Whether to include the field in SQL SELECT. Set to false for computed/virtual fields that have no database column (e.g. accessors).
is_relation bool true Whether sub-fields represent an Eloquent relationship. Set to false for JSON columns or cast arrays.
always string\|string[] - Additional columns always included in SELECT when this field is requested. Useful for computed properties that depend on other columns.
query Closure - Custom query callback applied to the Eloquent eager-loading query for this relation.
alias string\|Closure\|Expression field name Maps a GraphQL field name to a different database column or relation method name.

Eager Loading Relationships

The profile and posts relations must also exist on the User Eloquent model. If some fields are required for the relation to load or for validation, you can define an always attribute that will add the given attributes to select.

The attribute can be a comma separated string or an array of attributes to always include.

At this point we have a profile and a post type as expected for any model:

Custom Relation Queries

You can specify a query callback that will be applied to the Eloquent eager-loading query for a relation:

Pagination

Pagination will be used if a query or mutation returns a PaginationType.

Note that unless you use resolver middleware, you will have to manually supply both the limit and page values:

Query posts(limit:10,page:1){data{id},total,per_page} might return:

Note that you need to add the extra data object when you request paginated resources, as the returned data gives you the paginated resources in a data object at the same level as the returned pagination metadata.

Simple Pagination

Simple Pagination will be used if a query or mutation returns a SimplePaginationType.

SimplePaginationType exposes the following fields: data (the paginated items), per_page, current_page, from, to, and has_more_pages. Unlike full pagination, total and last_page are not available.

Cursor Pagination

Cursor Pagination will be used if a query or mutation returns a CursorPaginationType.

CursorPaginationType exposes the following fields: data (the paginated items), per_page, previous_cursor (String, nullable), and next_cursor (String, nullable).

Pagination type auto-replacement

This package automatically replaces the core pagination types with SelectFields-aware subclasses. The subclasses implement WrapType (so SelectFields can traverse into the paginated data) and mark metadata fields like total, per_page, etc. as selectable: false (so they are not included in SQL SELECT).

If you have set a custom pagination type in your config, the package will not override it.

JSON Columns

When using JSON columns in your database, the field won't be defined as a "relationship", but rather a simple column with nested data. Use the is_relation attribute to tell SelectFields not to treat it as an Eloquent relation:

Wrap Types

If you use SelectFields in a query that returns a wrap type, your wrapper class must implement the WrapType marker interface. This tells SelectFields to look through the wrapper's data field to find the underlying model type and generate the correct SELECT/WITH clauses.

The package's pagination types already implement this interface. Custom pagination classes configured via the pagination_type, simple_pagination_type, or cursor_pagination_type config keys must also implement it.

Abstract Types (Unions and Interfaces)

When using SelectFields with union or interface types, custom query callbacks on relation fields defined in member/concrete types are supported. SelectFields will match the concrete type at eager-load time and apply the callback automatically.

Note: When a query includes inline fragments on multiple member types that each request different relations, SelectFields will merge all requested relations into the eager-load set.

Note: For union types, SelectFields cannot determine the concrete type at query-build time, so it uses SELECT * instead of selecting specific columns.

API Reference

SelectFields

WrapType

SelectFieldsParameterInjector

Implements Rebing\GraphQL\Support\Contracts\ResolverParameterInjector. This is registered automatically by the service provider. You only need to interact with it if you're building a custom SelectFields subclass:

Known Limitations

License

MIT


All versions of graphql-laravel-select-fields with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^12.0|^13.0
rebing/graphql-laravel Version ^10.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rebing/graphql-laravel-select-fields contains the following files

Loading the files please wait ...