# Adding Types Programmatically

You might want to add additional types to the schema programmatically.

# Additional Schema Definitions

If you want to use the SDL to define additional types dynamically, you can listen for the BuildSchemaString event and add in schema definitions as a simple string.

# Native PHP types

While Lighthouse is a schema first GraphQL server and primarily uses the SDL, you can also use native PHP type definitions.

Check out the webonyx/graphql-php documentation (opens new window) on how to define types.

Note that you will not have access to a large portion of Lighthouse functionality that is provided through server-side directives and the definition is much more verbose.

Because of this, we do not recommend you use native PHP types for complex object types.

However, it can be advantageous to use native types for two use cases:

# Using the TypeRegistry

Lighthouse provides a type registry out of the box for you to register your types. You can get an instance of it through the Laravel Container.



namespace App\Providers;

use GraphQL\Type\Definition\Type;
use Illuminate\Support\ServiceProvider;
use GraphQL\Type\Definition\ObjectType;
use Nuwave\Lighthouse\Schema\TypeRegistry;

class GraphQLServiceProvider extends ServiceProvider
     * Bootstrap any application services.
     * @param TypeRegistry $typeRegistry
     * @return void
    public function boot(TypeRegistry $typeRegistry): void
             new ObjectType([
                 'name' => 'User',
                 'fields' => function() use ($typeRegistry) {
                     return [
                         'email' => [
                             'type' => Type::string()
                         'friends' => [
                             'type' => Type::listOf(