Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate NewDefaultServer #3404

Merged
merged 2 commits into from
Dec 5, 2024
Merged

Conversation

StevenACoffman
Copy link
Collaborator

@StevenACoffman StevenACoffman commented Dec 3, 2024

This was only there for tests and as an example, but people have tried to use it in their production environments and found out the hard way it wasn't intended for that. Deprecating will hopefully make this more clear.

However, all the deprecation warnings for all the test usage cause the linter to fail. 😢

I don't know of a great solution, so if you have a suggestion for how to fix this, I would appreciate it.

I'm not sure of a great way to make a test only equivalent function without using a special build constraint tag that would then cause more people to stumble on more regular go test ./...

I could add a //nolint:staticcheck // SA1019: handler.NewDefaultServer is deprecated but usage for test is ok everywhere, but that ignores all staticcheck checks, not just the deprecation one.

I could copy-paste the NewDefaultserver function to be nested inside the various call sites, but that's a lot of duplication.

Signed-off-by: Steve Coffman steve@khanacademy.org

Signed-off-by: Steve Coffman <steve@khanacademy.org>
@coveralls
Copy link

coveralls commented Dec 3, 2024

Coverage Status

coverage: 59.668% (-0.2%) from 59.861%
when pulling ca4954c on deprecate_new_default_server
into 3736848 on master.

@StevenACoffman StevenACoffman marked this pull request as draft December 3, 2024 19:01
@StevenACoffman StevenACoffman added the help wanted Extra attention is needed label Dec 3, 2024
@phughes-scwx
Copy link
Contributor

What help do you want?

@StevenACoffman
Copy link
Collaborator Author

All the deprecation warnings for all the test usage cause the linter to fail. 😢

I don't know of a great solution, so if you have a suggestion, I would appreciate it.

I'm not sure of a great way to make a test only equivalent function without using a special build constraint tag that would then cause more people to stumble on more regular go test ./...

I could add a //nolint:staticcheck // SA1019: handler.NewDefaultServer is deprecated but usage for test is ok everywhere, but that ignores all staticcheck checks, not just the deprecation one.

I could copy-paste the NewDefaultserver function to be nested inside the various call sites, but that's a lot of duplication.

@phughes-scwx
Copy link
Contributor

phughes-scwx commented Dec 3, 2024

I can make a pass over it. I think, if you are deprecating something, you should go ahead and remove it from internal code. I can get a glass of red, listen to a podcast, and start ctrl-v-ing a whole bunch.

@phughes-scwx
Copy link
Contributor

#3406 has this branch as its base, as I can not push directly.

* replace in init server template

* update _examples

* update plugin tests

* grep default setup across testserver/singlefile with test helper

* replace all other cases in testserver/singlefile

* replace testserver/nullabledirectives

* grep testserver/followschema with test helper; fix all other cases

* replace all test helpers with code

* lint

* docs: introspection (big change)

* docs: simple replacements in code examples

* docs: overhaul of subscriptions

* add introspection to federation example for js tests
@StevenACoffman StevenACoffman marked this pull request as ready for review December 5, 2024 12:26
@StevenACoffman StevenACoffman merged commit 773fa3c into master Dec 5, 2024
17 of 18 checks passed
@StevenACoffman StevenACoffman deleted the deprecate_new_default_server branch December 5, 2024 13:28
@StevenACoffman
Copy link
Collaborator Author

Thanks again!

@idc77
Copy link

idc77 commented Dec 21, 2024

How do you propose to replace it and what did "they find out the hard way"?

@StevenACoffman
Copy link
Collaborator Author

@idc77

In the code, the comment for it now tries to explain that you should make your own local version of it, customized to suit your own needs (only add the transports you want, and customize the cache and transports to match your workloads):

// NewDefaultServer is a demonstration only. Not for prod.
//
// Currently, the server just picks the first available transport,
// so this example NewDefaultServer orders them, but it is just
// for demonstration purposes.
// You will likely want to tune and better configure Websocket transport
// since adding a new one (To configure it) doesn't have effect.
//
// Also SSE support is not in here at all!
// SSE when used over HTTP/1.1 (but not HTTP/2 or HTTP/3),
// SSE suffers from a severe limitation to the maximum number
// of open connections of 6 per browser. See:
// https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#sect1
//
// Deprecated: This was and is just an example.
func NewDefaultServer(es graphql.ExecutableSchema) *Server {
	srv := New(es)

	srv.AddTransport(transport.Websocket{
		KeepAlivePingInterval: 10 * time.Second,
	})
	srv.AddTransport(transport.Options{})
	srv.AddTransport(transport.GET{})
	srv.AddTransport(transport.POST{})
	srv.AddTransport(transport.MultipartForm{})

	srv.SetQueryCache(lru.New[*ast.QueryDocument](1000))

	srv.Use(extension.Introspection{})
	srv.Use(extension.AutomaticPersistedQuery{
		Cache: lru.New[string](100),
	})

	return srv
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants