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

strange symbols in generated code #3413

Open
vtolstov opened this issue Dec 8, 2024 · 5 comments
Open

strange symbols in generated code #3413

vtolstov opened this issue Dec 8, 2024 · 5 comments

Comments

@vtolstov
Copy link

vtolstov commented Dec 8, 2024

unmarshalN__DirectiveLocation2ᚕstringᚄ

in generated file i can see strange symbols, does it possible to generate code only with standard symbols ?

my schema:

directive @AccountService on FIELD_DEFINITION
type Account {
	id: String
	parent: String
	zone: String
	status: AccountStatus
	login: String
	passw: String
	type: AccountType
	createdAt: Int
	updatedAt: Int
	deletedAt: Int
	info: AccountInfo
	metadata: [Account_MetadataEntry!]
}
enum AccountAddress {
	ACCOUNT_ADDRESS_UNSPECIFIED
	ACCOUNT_ADDRESS_REGISTRATION
	ACCOUNT_ADDRESS_CURRENT
	ACCOUNT_ADDRESS_CORPORATE
}
type AccountInfo {
	name: String
	email: String
	id: String
	contacts: [Contact!]
	addresses: [Address!]
}
enum AccountStatus {
	ACCOUNT_STATUS_UNSPECIFIED
	ACCOUNT_STATUS_DISABLED
	ACCOUNT_STATUS_ENABLED
	ACCOUNT_STATUS_BLOCKED
	ACCOUNT_STATUS_DELETED
}
enum AccountType {
	ACCOUNT_TYPE_UNSPECIFIED
	ACCOUNT_TYPE_PRIVATE
	ACCOUNT_TYPE_CORPORATE
}
type Account_MetadataEntry {
	key: String
	value: String
}
type Address {
	type: AccountAddress
	value: String
}
type Contact {
	type: ContactType
	value: String
}
enum ContactType {
	CONTACT_TYPE_UNSPECIFIED
	CONTACT_TYPE_EMAIL
	CONTACT_TYPE_PHONE
	CONTACT_TYPE_MESSENGER
}
input CreateAccountReqInput {
	name: String
}
type ListAccountRsp {
	accounts: [Account!]
}
type Mutation {
	accountServiceCreateAccount(in: CreateAccountReqInput): Boolean @AccountService
	accountServiceUpdateAccount: Boolean @AccountService
	accountServiceDeleteAccount: Boolean @AccountService
}
type Query {
	accountServiceListAccount: ListAccountRsp @AccountService
	accountServiceLookupAccount: Boolean @AccountService
}

@vtolstov
Copy link
Author

vtolstov commented Dec 9, 2024

func TypeIdentifier(t types.Type) string {
	res := ""
	for {
		switch it := code.Unalias(t).(type) {
		case *types.Pointer:
			t.Underlying()
			res += "ᚖ"
			t = it.Elem()
		case *types.Slice:
			res += "ᚕ"
			t = it.Elem()
		case *types.Named:
			res += pkgReplacer.Replace(it.Obj().Pkg().Path())
			res += "ᚐ"
			res += it.Obj().Name()
			return res
		case *types.Basic:
			res += it.Name()
			return res
		case *types.Map:
			res += "map"
			return res
		case *types.Interface:
			res += "interface"
			return res
		default:
			panic(fmt.Errorf("unexpected type %T", it))
		}
	}
}

@Brookke
Copy link
Contributor

Brookke commented Dec 18, 2024

@vtolstov Is this causing an issue or is this just a style issue?

@vtolstov
Copy link
Author

mostly this is style issue and i don't understand why we need to use such symbols (also my ci warns about non ascii symbols in code)

@Brookke
Copy link
Contributor

Brookke commented Dec 20, 2024

Could replace the symbols in the TypeIdentifier here with words e.g.

func TypeIdentifier(t types.Type) string {
	res := ""
	for {
		switch it := code.Unalias(t).(type) {
		case *types.Pointer:
			t.Underlying()
			res += Pointer"
			t = it.Elem()
		case *types.Slice:
			res += "Slice"
			t = it.Elem()
		case *types.Named:
			res += pkgReplacer.Replace(it.Obj().Pkg().Path())
			res += "Named"
			res += it.Obj().Name()
			return res
		case *types.Basic:
			res += it.Name()
			return res
		case *types.Map:
			res += "Map"
			return res
		case *types.Interface:
			res += "Interface"
			return res
		default:
			panic(fmt.Errorf("unexpected type %T", it))
		}
	}
}

there is also

var pkgReplacer = strings.NewReplacer(
"/", "ᚋ",
".", "ᚗ",
"-", "ᚑ",
"~", "א",
)

but not sure what to propose as replacements here

@vtolstov
Copy link
Author

may be this is time to change this?

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

No branches or pull requests

2 participants