Skip to content
New issue

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

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

Already on GitHub? # to your account

Add mechanism for generating public query functions and types #287

Closed
fmoor opened this issue Oct 4, 2023 · 9 comments · Fixed by #318
Closed

Add mechanism for generating public query functions and types #287

fmoor opened this issue Oct 4, 2023 · 9 comments · Fixed by #318

Comments

@fmoor
Copy link
Member

fmoor commented Oct 4, 2023

Currently edgeql-go generates private query functions and return types. The user can export these types but it requires a few lines of code for each query. There should be a way to make the generator generate public instead of private functions and types.

Maybe this should be configurable on a per query basis?

@chirino
Copy link

chirino commented May 5, 2024

I would default to being public, if a user really wants to keep it private he can place it under an internal directory so that it's public to external packages.

chirino added a commit to chirino/edgedb-go that referenced this issue May 5, 2024
* -pubtypes make the generated types public
* -pubfuncs makes the generated functions public
* -jsontag add a `json:”...”` field tag

Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
@fmoor
Copy link
Member Author

fmoor commented May 6, 2024

I would default to being public, if a user really wants to keep it private he can place it under an internal directory so that it's public to external packages.

Public by default seems reasonable, but I think there should still be a way to make them private to a package. In a large enough project it is reasonable to want to restrict some things more than just internal/.

@GenarLoya
Copy link

Hello, a little question, @fmoor, triying use the flag -pubfuncs not working, I suppose is not in the current release, can you help me to pass private to public, without modify generated files?

@fmoor
Copy link
Member Author

fmoor commented Jun 25, 2024

Hello, a little question, @fmoor, triying use the flag -pubfuncs not working, I suppose is not in the current release, can you help me to pass private to public, without modify generated files?

This is not implemented yet. You can achieve the same thing by putting this in a non generated file in the same package.

var MyQueryFunc = myQueryFunc

I'll try to get this implemented soon.

fmoor added a commit that referenced this issue Jun 25, 2024
fmoor added a commit that referenced this issue Jun 26, 2024
fmoor added a commit that referenced this issue Jul 1, 2024
@fmoor fmoor closed this as completed in #318 Jul 2, 2024
@fmoor fmoor closed this as completed in 76d079b Jul 2, 2024
@mdthompson-helium
Copy link

mdthompson-helium commented Jul 2, 2024

pubtypes generates a public struct but its fields are all private if the fields in the .esdl are lower case. Is best practice to name those fields so they will be generated so they are public or generate the return type by default with public fields if you use pubtypes?

@fmoor
Copy link
Member Author

fmoor commented Jul 2, 2024

pubtypes generates a public struct but its fields are all private. Was it intentional to keep these private as well?

Yes. In EdgeQL it is possible to have both a Name and a name property in a shape/type. Because of this the default behavior is to preserved field names exactly as you spell them in your query. You can change this by either using the -mixedcaps flag or by using mixed caps names in your query. For example:

select schema::Function {
  Name := .name,
  Language := .language,
  Params := .params {
    Name := .name,
    Default := .default,
  }
}

You could also define your types with mixed caps names so you don't need to rename everything in every query.

@fmoor
Copy link
Member Author

fmoor commented Jul 2, 2024

Is best practice to name those fields so they will be generated so they are public or generate the return type by default with public fields if you use pubtypes?

I don't think there is an established best practice here. For most schemas it is probably easiest to use -mixedcaps.

@mdthompson-helium
Copy link

Yes. In EdgeQL it is possible to have both a Name and a name property in a shape/type. Because of this the default behavior is to preserved field names exactly as you spell them in your query. You can change this by either using the -mixedcaps flag or by using mixed caps names in your query.

Thanks, that helped clarify the behavior

@fmoor
Copy link
Member Author

fmoor commented Jul 9, 2024

The new -pubfucs and -pubtypes options for the code generator are available in v0.17.2

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants