edgedb-go icon indicating copy to clipboard operation
edgedb-go copied to clipboard

Add mechanism for generating public query functions and types

Open fmoor opened this issue 2 years ago • 2 comments

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?

fmoor avatar Oct 04 '23 21:10 fmoor

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 avatar May 05 '24 12:05 chirino

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/.

fmoor avatar May 06 '24 21:05 fmoor

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?

GenarLoya avatar Jun 25 '24 02:06 GenarLoya

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 avatar Jun 25 '24 18:06 fmoor

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?

mdthompson-helium avatar Jul 02 '24 21:07 mdthompson-helium

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 avatar Jul 02 '24 21:07 fmoor

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.

fmoor avatar Jul 02 '24 21:07 fmoor

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

mdthompson-helium avatar Jul 02 '24 21:07 mdthompson-helium

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

fmoor avatar Jul 09 '24 17:07 fmoor