Lighthouse: ide-helper command generating broken schema-directives.graphql file

Created on 13 Jan 2021  路  8Comments  路  Source: nuwave/lighthouse

Let me prefix this by saying thanks for creating a great library for the OS community! 馃帀

Describe the bug
The installation docs recommend installing the popular JS GraphQL plugin for PHPStorm and using the php artisan lighthouse:ide-helper command to generate schema files that the plugin can use for helpful autocomplete/suggestion functionality.

However, at least one of these files contains errors that prevent the aforementioned plugin functionality from working.

Expected behavior/Solution
Lighthouse directives defined in the generated 'schema-directives.graphql' file, e.g. @scalar and @all should be recognised by the IDE (i.e. no error should display) and CTRL+clicking should navigate through to the relevant area of the schema (as per the plugin's standard functionality).

screenshot of problem with plugin

I originally thought this was a problem with the plugin itself and that its default configuration wasn't importing the files correctly, due to the main schema not being in the project's route. Although, this turned out to be a red-herring as the IDE plugin displays a clear error when viewing a file that is not being imported. Instead, I discovered the 'schema-directives.graphql' file contains a number of errors:

list of schema errors

The problems include missing type definitions, duplicate definitions and syntax errors, for example:

Steps to reproduce

  1. Start with a fresh Laravel 8.21 installation
  2. Install Lighthouse 5.0 (composer require nuwave/lighthouse)
  3. Install the JS GraphQL plugin for PHPStorm (https://plugins.jetbrains.com/plugin/8097-js-graphql)
  4. Generate the helper schemas (php artisan lighthouse:ide-helper)
  5. Open your project's 'graphql/schema.graphql' file in PHPStorm and attempt to use some basic lighthouse directives, such as @all.

Output/Logs
I patched the problem by hand, which is obviously not ideal, but it should hopefully illustrate the problem quite clearly if you look at the diff: https://www.diffchecker.com/7gLvXXor

Lighthouse Version
5.0

question

Most helpful comment

Thanks @SamChristy for the report and @lorado for the update.

You can temporarily strip the repeatable keyword from the directive definitions, until the plugins catch up:

sed -i 's/repeatable//g' schema-directives.graphql

All 8 comments

Hi @SamChristy
I can feel your pain =)
repeatable is a new gql feature, that is currently not supported by js-graphql intellij plugin, but it is under development. You can follow this issue, to stay updated on the task: https://github.com/jimkyndemeyer/js-graphql-intellij-plugin/issues/351
I guess, when repeatable becomes recognizable by js-graphql intellig plugin, all the errors will disappear.

If not, we can then continue fixing possible issues.

Thanks @SamChristy for the report and @lorado for the update.

You can temporarily strip the repeatable keyword from the directive definitions, until the plugins catch up:

sed -i 's/repeatable//g' schema-directives.graphql

I just looked at the diff you posted, there is some stuff worth discussing:

  • Adding the base types: We would have to check if the user has already defined them, otherwise you run into another error. Not sure if we can easily recognize that.
  • RulesMessageMap unfortunately is currently implemented in a way that makes it impossible to define an accurate directive definition, as generic maps are not possible in GraphQL. Working on it in https://github.com/nuwave/lighthouse/pull/1662
  • BelongsToManyType was missing because of hasty copy-and-paste, fixed in https://github.com/nuwave/lighthouse/pull/1663
  • Mixed is a tricky one, some people define that scalar themselves. We could probably include it somewhere?

Thanks guys,
@lorado that's really useful to know, re the repeatable feature missing on the PHPStorm plugin. 馃憤

@spawnia thank you for going through each of the issues so thoroughly; I'm very glad to hear that two of the problems are already being addressed. In regards to the others:

  1. Base Types - I tested this locally, with type Query defined in both the helper schema ('schema-directives.graphql) and my main actual schema ('graphql/schema.graphql'), and there was no issue I could see - the IDE plugin didn't report any errors and the query I defined continued to work, when I made a request targeting it.
    So I'm not sure what the problem would be here?
  2. Mixed Type - Similarly to my previous point, I was able to define the Mixed type without issue, so I think the schema-directives.graphql file should be able to contain this, unless I am missing something? (In which case I'm sorry!)
  3. Duplicate Definition - enum PaginateType is defined twice in schema-directives.graphql - I'm not sure what the cause is, but it should hopefully be easier to solve?

I think, overall, the expectation from a new user's perspective is that everything in the intro tutorial will just work out of the box. I also think more experienced users (who are defining Mixed, etc.) may be better able to work around any issues arising from more advanced use-cases.
I wonder if adding optional flags to the php artisan lighthouse:ide-helper command, e.g. --exclude-base-types, could offer a good middle ground? I would be happy to put in a PR for that, if desired. 馃憤

You can temporarily strip the repeatable keyword from the directive definitions, until the plugins catch up:

sed -i 's/repeatable//g' schema-directives.graphql

For people finding this, on OS X the correct command to strip out the repeatable keyword is:

sed -i '' 's/repeatable//g' schema-directives.graphql

Linux and OS X sed commands are slightly different and are not 1:1 compatible.

What does the Mixed definition depend on generally? Is there any documentation on what Mixed should or could be? If not, would someone be as kind as to provide a good definition of it? Sorry if I've missed something!

What does the Mixed definition depend on generally? Is there any documentation on what Mixed should or could be? If not, would someone be as kind as to provide a good definition of it? Sorry if I've missed something!

It is now excluded from Lighthouse's directive definitions.

I still encounter these problems. I'm currently using the latest version 5.3.

  • repeatable are unknown
  • Unknown input like [RulesMessage, RulesForArrayMessage, ....] (because they are being used before declaration)
  • All directive declaration will be ignore after the first error
Was this page helpful?
0 / 5 - 0 ratings

Related issues

vine1993 picture vine1993  路  3Comments

let-aurn picture let-aurn  路  3Comments

mikeerickson picture mikeerickson  路  3Comments

alexwhb picture alexwhb  路  4Comments

nguyentrongbang picture nguyentrongbang  路  3Comments