Skip to content

Add formatter.WithNonIntrospectionBuiltin#415

Merged
StevenACoffman merged 8 commits intovektah:masterfrom
fredzqm:fz/formatter-nonintrospect-builtin
Feb 19, 2026
Merged

Add formatter.WithNonIntrospectionBuiltin#415
StevenACoffman merged 8 commits intovektah:masterfrom
fredzqm:fz/formatter-nonintrospect-builtin

Conversation

@fredzqm
Copy link
Contributor

@fredzqm fredzqm commented Feb 14, 2026

formatter.WithBuiltin uses two criteria to determine what is a builtin schema:

A) The Definition.Builtin or .Position.Src.BuiltIn
B) The type name or field name starts with __, commonly associated with Graphql's introspection API.

I ran into a case where I want the formatter to print all builtin types, fields and directives without __typename, __schema, so the end result is still considered a valid Graphql. Duplicating builtin scalars and ID is considered valid in graphql-js, but not the introspection fields.

The existing option formatter.WithBuiltin will render types & fields that match either A) or B).
The new option formatter.WithNonIntrospectionBuiltin will render types & fields that match A), but still exclude introspection fields.

I have:

  • Added tests covering the bug / feature
  • Updated any relevant documentation

@coveralls
Copy link

coveralls commented Feb 14, 2026

Coverage Status

coverage: 87.218% (+0.04%) from 87.18%
when pulling c60fde3 on fredzqm:fz/formatter-nonintrospect-builtin
into 48a3d5e on vektah:master.

@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Feb 15, 2026

Thanks, and sorry for the format hassles!

I recently altered the .golangci-lint so you should be able fix any formatting by just running:

golangci-lint fmt --config=../.golangci.yaml .

Which if you don't have golangci-lint installed (and don't mind YOLO'ing it!) you can use this script:

#!/bin/bash

# this will format the code locally

function is_bin_in_path {
  builtin type -P "$1" &> /dev/null
}

function fmtall {
    export GOBIN="$HOME/go/bin"
    mkdir -p "$GOBIN"

    ! is_bin_in_path golangci-lint && GOBIN=$HOME/go/bin curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOBIN latest
    export PATH="$GOBIN:$PATH"

    golangci-lint fmt --config=./golangci.yaml .
}

fmtall

Or, you can use golangci-lint's recommended installation instructions and do things one of the normal, safe (and sane) ways. 😅

@fredzqm
Copy link
Contributor Author

fredzqm commented Feb 15, 2026

Thanks for the pointer!

Installed golangci-lint the using the recommended instruction.

Just ran and pushed the last commit.

golangci-lint fmt --config=.golangci.yaml .

However, I still see this error in CI, which looks like an existing issue in master's CI result

Run golangci/golangci-lint-action@v9.2.0
Restore cache
Install
run golangci-lint
  Running [/home/runner/golangci-lint-2.9.0-linux-amd64/golangci-lint config path] in [/home/runner/work/gqlparser/gqlparser] ...
  Running [/home/runner/golangci-lint-2.9.0-linux-amd64/golangci-lint config verify] in [/home/runner/work/gqlparser/gqlparser] ...
  Running [/home/runner/golangci-lint-2.9.0-linux-amd64/golangci-lint run  --timeout 5m] in [/home/runner/work/gqlparser/gqlparser] ...
  Error: ast/dumper.go:153:9: reflectvaluecompare: avoid using reflect.DeepEqual with reflect.Value (govet)
  	return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()))
  	       ^
  1 issues:
  * govet: 1
  
  Error: issues found
  Ran golangci-lint in 20539ms

@fredzqm
Copy link
Contributor Author

fredzqm commented Feb 17, 2026

@StevenACoffman

To help unblock this PR, I took a stab at the existing linter errors in this repos. #416 should take care of them with no behavior change.

Let me know if the fix is reasonable~

This PR will unblock an upcoming launch that we have. If it takes a bit to get in, we may consider creating a temporary folk. Hopefully, we can avoid it. Appreciate your timely feedback and reviews!

PS: Love those linter improvements. Our internal tooling flagged them as well when we import them~

@fredzqm
Copy link
Contributor Author

fredzqm commented Feb 18, 2026

@StevenACoffman Let me know if there are anything I can do to get this PR unblocked~ Thanks a lot!

@StevenACoffman StevenACoffman merged commit d828d64 into vektah:master Feb 19, 2026
6 checks passed
@StevenACoffman
Copy link
Collaborator

@fredzqm This was great! I'm sorry, I was actually away travelling for a week and am just catching up!

@StevenACoffman
Copy link
Collaborator

@fredzqm I cut a v2.5.32 release including this feature https://github.com/vektah/gqlparser/releases/tag/v2.5.32

@fredzqm
Copy link
Contributor Author

fredzqm commented Feb 19, 2026

Nice! Thanks you @StevenACoffman for unblocking me!🙏🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments