question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best way to rename field?

See original GitHub issue

I have a property named IPAddress, and its converted to iPAddress what is the best way to rename it?

Currently i do the following:

schema.Type<Device>().RemoveField(x => x.IPAddress);
schema.Type<Device>().AddField("ipAddress", x => x.IPAddress, "");

The downside i have found is that i loose all comments that i have applied using the Description attribute. (Same thing happens with MACAddress)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AnderssonPetercommented, Sep 18, 2020

@lukemurray the AddMutationFrom does not have a fieldNamer argument so the input arguments there still get incorrectly renamed.

How about storing the one that gets sent into FromObject that way we don’t have to send a new one with every AddType.

"kind": "OBJECT",
"name": "Mutation",
"description": "The mutation type, represents all updates we can make to our data",
"fields": [{
	"name": "addDevice",
	"description": null,
	"args": [{
			"name": "mACAddress", <---
			"description": null,
			"type": {
				"kind": "NON_NULL",
				"name": null,
				"ofType": {
					"kind": "SCALAR",
					"name": "String",
					"ofType": null
				}
			},
			"defaultValue": null
		}, {
			"name": "iPAddress", <---
			"description": null,
			"type": {
				"kind": "NON_NULL",
				"name": null,
				"ofType": {
					"kind": "SCALAR",
					"name": "String",
					"ofType": null
				}
			},
			"defaultValue": null
		}, {

Or if you want a function that handles this correctly (I have tested all combinations i can think of but i might have missed something):

private static string FieldNamer(MemberInfo memberInfo)
{
    var name = memberInfo.Name;
    for (var i = 0; i < name.Length; i++)
    {
        if (!char.IsUpper(name[i]))
        {
            if (i == 0)
            {
                return name;
            }
            if (i == 1)
            {
                return name.Substring(0, i).ToLower() + name.Substring(i);
            }
            else
            {
                return name.Substring(0, i - 1).ToLower() + name.Substring(i - 1);
            }
        }
    }
    return name.ToLower();
}
1reaction
lukemurraycommented, Jun 5, 2020

Whoops thanks.


From: Peter notifications@github.com Sent: Friday, June 5, 2020 1:57:20 AM To: lukemurray/EntityGraphQL EntityGraphQL@noreply.github.com Cc: Luke Murray lukemurray@gmail.com; Comment comment@noreply.github.com Subject: Re: [lukemurray/EntityGraphQL] Best way to rename field? (#46)

I think i found a bug https://github.com/lukemurray/EntityGraphQL/blob/74f8d576870eb4cfc31a3a2fc4607bdf058eb513/src/EntityGraphQL/Schema/SchemaBuilder.cs#L46 the fieldRenamer is never passed to the other method.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/lukemurray/EntityGraphQL/issues/46#issuecomment-638947686, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AABGHUOYT3GO5GCYU3BM2HTRU676BANCNFSM4M5ZZYAQ.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 ways to rename a field in Tableau
Drop Down & Rename: click on the drop down on top of the field name, select rename, rename and click enter. 2. Double...
Read more >
Rename a Field in a Table in Access - Instructions and ...
Then click into the “Field Name” column of the field whose name you wish to change. Type a new name for the field....
Read more >
Renaming Fields / Relabeling Fields
Renaming Standard Fields · Click the gear icon at the top of the page, next click Edit Object. · In the object menu,...
Read more >
How To Rename Column Name In SQL? - Edureka
The RENAME command is used to rename column name in sql. ALTER TABLE TableName RENAME COLUMN OldColumnName TO NewColumnName;
Read more >
Renaming a field—ArcMap | Documentation
The Table Fields tab appears. Table Fields tab. Right-click a Name or Alias cell and click Rename. Type the new name for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found