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

EF issue - user is a value type and cannot be selected from #92

Closed
bobloblaws93 opened this issue Mar 26, 2018 · 8 comments
Closed

EF issue - user is a value type and cannot be selected from #92

bobloblaws93 opened this issue Mar 26, 2018 · 8 comments

Comments

@bobloblaws93
Copy link

Hi, all
I'm having a bit of an issue with graphql. I'm trying to query my dataset but im running into problems the moment I try execute a query. I get the exeception:

GraphQL.Parser.SourceException: 'field ``user'' is a value type and cannot be selected from'

My code is as follows:

   public void test() {
         var schema = GraphQL<AdtDbContext>.CreateDefaultSchema(() => new AdtDbContext());
         schema.AddType<NTC_TC_MAINS>().AddAllFields();            
         var gql = new GraphQL<AdtDbContext>(schema);
         schema.AddField("user", new { NAME = "-1" }, (db, args) => db.NTC_TC_MAINS.SingleOrDefault(u => u.TC_NAME == args.NAME));
         schema.Complete();
         var qresult = gql.ExecuteQuery("{user(NAME:\"Hudson\") {tC_NAME}}");
         Console.WriteLine(JsonConvert.SerializeObject(qresult, Formatting.Indented));
        }

With the following DBset:
public DbSet<NTC_TC_MAINS> NTC_TC_MAINS { get; set; }

typeselectedfrom

The exception is as follows is as follows:
GraphQL.Parser.SourceException occurred
HResult=0x80131500
Message=field ``user'' is a value type and cannot be selected from
Source=GraphQL.Parser
StackTrace:

Any advice into solving this would be greatly helpful!

@chkimes
Copy link
Owner

chkimes commented Mar 26, 2018

What's the query you're running? Is NTC_TC_MAINS a class or a struct?

@bobloblaws93
Copy link
Author

Thanks for Replying!
NTC_TC_MAINS is a class as is defined as follows:

namespace ATD.Domain.Entities
{
    [Table("NTC_TC_MAINS")]
    public class NTC_TC_MAINS
    {
        [Key]
        [MaxLength(100)]
        public string ID { get; set; }
        [Required]
        [MaxLength(1000)]
        public string TC_NAME { get; set; }
        [Required]
        public int TC_TYPE_ID { get; set; }
        [Required]
        public int TC_SUB_TYPE_ID { get; set; }
        [Required]
        public int TC_CERT_TYPE_ID { get; set; }
        [MaxLength(200)]
        public string TC_CERT_DOC { get; set; }
        [MaxLength(200)]
        public string TC_LOGO { get; set; }
        [MaxLength(4000)]
        public string TC_VISION { get; set; }
        [MaxLength(4000)]
        public string TC_DESC { get; set; }
        [Required]
        public int TC_AFFI_ID { get; set; }
     }
}

The main query im trying to run is to find any NTC_TC_MAIN with the name "Hudson".

    {
     user(NAME:\"Hudson\") 
      {
        tC_NAME,tC_LOGO,tC_VISION
      }
    }

I was running into a similar issue as #49, where I inherited a database with names that are all uppercased.

I don't know if it helps but everything works fine the moment I I grab a list and instantiate a new context like so, it works:

        class Context
        {
            public IList<NTC_TC_MAINS> ntc { get; set; }
        }

        public void test()
        {
            List<NTC_TC_MAINS> allTCs = null;
            using (AtduDbContext context = new AtduDbContext())
            {
                allTCs = context.NTC_TC_MAINS.Select(t => (t)).ToList();

                var schema = GraphQL<Context>.CreateDefaultSchema(() =>
                    new Context
                    {
                        ntc = allTCs
                    });
                schema.AddType<NTC_TC_MAINS>().AddAllFields();
                schema.AddField("user", new { NAME = "-1" }, (C, args) => C.ntc.SingleOrDefault(u => u.TC_NAME == args.NAME));
                schema.Complete();
                var gql = new GraphQL<Context>(schema);
                var qresult = gql.ExecuteQuery("{user(NAME:\"Hudson\") {tC_NAME,tC_LOGO,tC_VISION}}");
                System.Diagnostics.Debug.Write("graphsqlul" + (JsonConvert.SerializeObject(qresult, Formatting.Indented)));
            }

But I don't want to call and grab the entire list all the time. Would rather be able to run the graphQL query and filter based on that.

@chkimes
Copy link
Owner

chkimes commented Mar 26, 2018

Can you try using FirstOrDefault?

@bobloblaws93
Copy link
Author

changed to:
schema.AddField("user", new { id = "-1" }, (db, args) => db.NTC_TC_MAINS.Where(u => u.TC_NAME == args.id).FirstOrDefault());
Still gives me the same exception though

@chkimes
Copy link
Owner

chkimes commented Mar 27, 2018 via email

@bobloblaws93
Copy link
Author

Expanding the _fields gives:
prnt1
Expanding the type yields:
prnt2

@chkimes
Copy link
Owner

chkimes commented Mar 27, 2018 via email

@bobloblaws93
Copy link
Author

Oh man, you were absolutely right, NTC_MAIN was defined twice accidentally.
Everything works now, thank you so much!

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